static image does not show in Rails 5 application - asset-pipeline

I deployed a Rails 5 app (http://hedera1.ugent.be)
For some reason, one static image does not show on this page:
http://hedera1.ugent.be/projects
the static images are in the folder: /public/images
I show them in the page using the image_tag helper:
<%= image_tag "health.jpg" %>
<%= image_tag "elders.jpg" %>
for some reason <%= image_tag "elders.jpg" %> does not show in the page.
I don't understand why one image is showing but the other image isn't.
Any help is welcome,
Anthony

Related

Middleman Blog: Custom layout not loading

In Middleman, I am trying to set up a blog site, using custom layout for the blog. My problem is that the main layout is loading, but the blog layout for my articles is not. The article files are being served in with their plain body.
In source/layouts/ I have two files: layout.erb and article_layout.erb.
My intent is to use article_layout.erb for my blog articles.
In config.rb I have the following:
activate :blog do |blog|
blog.sources = "articles/{category}/{year}-{month}-{day}-{title}.html"
blog.layout = "article_layout"
end
I have also tried moving article_layout.erb to source/articles/ as well as prepending the config.rb file like this: blog.layout = "layouts/article_layout"
Another failed approach is to comment out the above option and configure the layout by adding this line instead: page "/articles/*", layout: "article_layout".
So far none of these approach show a difference. Since the default layout is not being rendered I would expect some sort of error message if the path to the layout cannot be found, but nothing shows up.
I managed to replicate your problem with my own Middleman blog setup.
The docs are unclear on this because there is a broken link in the layout section of Blogging.
You need to use the nested layout feature of Middleman and wrap your custom layout in:
<% wrap_layout :layout do %>
<% end %>
So your article_layout.erb would look something like this:
<% wrap_layout :layout do %>
<div class="article-container">
<article>
<h2 class="article-title"><%= current_page.title %></h2>
<%= yield %>
</article>
</div>
<% end %>
And keep your custom layout in the source/layouts folder.
Here are the docs for Nested Layouts for your reference.
I hope this helps.

Middleman: How can I get the current article title?

When generating a simple blog in Middleman using the "middleman-blog" extension I get a the layout file which simply yields the content of the post.
What I want is to get the title of the current post and display that.
What I have right now:
<% blog.articles.each do |article| %>
<%= link_to article.title, article %>
<% end %>
This loops through every post title even though only the single post content is displayed. So it outputs something like this for the url /post-title-one
Post Title One Post Title Two Post Title Three
"only the content of post title one"
I want to try something like
<% blog.articles.each do |article| %>
<%= link_to current_article.title, article %>
<% end %>
But it just randomly spits out two page titles.
If you want to print the current article's title just use <%= current_article.title %>.
I'm not quite sure what you're asking. The first block of code you gave is intended to iterate through each article in the blog and generate a link where the link text is the article's title and the target is the article. I would assume that you want to simply link to the current article, since you're on its content page.
<%= link_to current_article.title, current_article %>
That should get the job done.

MissingTemplate Frustrating behavior

I am completing this rails tutorial
Everything was going along smoothly even though im working on windows, until i hit the partials section.
I pretty much copy pasted everything from the tutorial. I made sure that the underscore character in the partial filenames is an actual underscore.
I have placed the partials in the
app/views/layouts/
path as the tutorial suggests and included the
<%= render 'layouts/shim' %>
in my application.html.erb file. This results in the
ActionView::MissingTemplate in StaticPages#home
Showing E:/ruby/my_projects/sample_app/app/views/layouts/application.html.erb where line #9 raised:
Missing partial layouts/shim with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
* "E:/ruby/my_projects/sample_app/app/views"
Extracted source (around line #9):
"data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %> #this is line number 9
</head>
<body>
<%= render 'layouts/header' %>
I have tried placing the files directly in views folder as well as in the static pages folder.
I restarted the rails server multiple times during this process.
Anybody has any ideas?
Ok I guess its a ridicules mistake but it took me so long to figure it out. It should be obvious for me that windows hides extensions so after i misnamed my file the first time and tried to fix it (rename it) it already hid the .erb extension. So it had an .erb.erb extension and because of that it didnt work.
Thanks everyone that tried to help.

What does <%anything%> do?

In Rails tutorials and vids, it seems totally different from regular ruby. For example, I see <%render%> or <%end%>. When am I supposed to use <%%> and what is it for?
<% code %> is used in erb, which stands for "Embedded Ruby". It's typically used in HTML generating templates. It's brother is <%= code %> which outputs the return value of the expression inside it.
<h1>Hello, <%= #user.name %>!</h1>
# potentially renders: <h1>Hello, Bob</h1>
# potentially renders: <h1>Hello, Sue</h1>
The non-outputting <% code %> version of this tag is useful for executing code, but not writing anything to the template. This is useful for conditionals (as well as other things).
<h1>
Hello
<% if #user.sex == 'male' %>
Mister
<% else %>
Miss
<% end %>
<%= #user.name %>!
</h1>
# potentially renders: <h1>Hello Mister Bob!</h1>
# potentially renders: <h1>Hello Miss Sue!</h1>
In pure ruby, this would be a syntax error. But within an erb template, these tags allow you to control how the template renders by executing ruby to control the template flow, and by writing out the result of ruby expressions.
Rails uses erb by default for it's views, which are mostly html generating templates. So you see this a lot in Rails examples. Just keep in mind that erb is just one option for your templates in Rails. There is a great many options, which may use different syntax entirely.
That is used in HTML code to display ruby code inside the tags.
<%= render 'folder/partial_form' %>
That will render a form partial.
I suggest you have a nice long read through the links below:
http://www.guides.rubyonrails.org
http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials
The <%= %> and <% %> syntax is used to write ruby in a .erb file. Think of ERB as an html file that always allows ruby code to be run. The <% %> syntax runs the ruby but does nothing by default while the <%= %> syntax(notice the =) outputs the result of the ruby code to the screen.

Commenting something out in Ruby ERB within the UI?

I have a .html.erb page and I am trying to comment something out using traditional HTML comments:
<!--
User Id (testing MySQL call): <%= #User.uid %>
-->
But since its a Ruby reference that I am commenting out, it isn't getting commented, and is generating ruby errors. How could I comment out such a thing? I also tried putting a # before that line, but that didn't work either.
In your ERB tags, to do a comment, use:
<%-# #User.uid %>
You'll still need the HTML comment tags wrapping the other text too.
You can comment out an ERB expression by changing the <%= into a <%#. This will not hide the HTML containing it from view, but you can combine HTML comments with the ERB comment to keep your application from throwing an error and hiding the surrounding HTML bits.
<!--
User Id (testing MySQL call): <%# #User.uid %>
-->
You can also comment a block with =begin and =end like this:
<%
=begin %>
<%= link_to "Sign up now!", signup_path, :class => "signup_button round" %>
<%
=end %>

Resources