One of my pages keeps hitting this error:
ActionView::Template::Error (undefined method `+' for nil:NilClass):
15: <div class="look_list">
16: <% collection.each do |look| %>
17: <div class="look_book" id="<%= look.content_id %>">
18: <% thumbnail_image = (look.processing? ? "/assets/processing_placeholder.gif" : (look.image.url(:thumb) + "?#{look.updated_at.to_i}")) %>
19: <%= image_tag thumbnail_image || "/assets/processing_placeholder.gif",:class=> "look_image", :size => "118x118" %>
20: <script type="text/javascript">
21:
app/views/looks/index.html.erb:18:in `block in _app_views_looks_index_html_erb__3409922204803071014_68666020'
app/views/looks/index.html.erb:16:in `_app_views_looks_index_html_erb__3409922204803071014_68666020'
Some background, my site hit into 502 bad gateway 2 days ago. We managed to restart the site. However, it caused some connection issue with mongodb. This was resolved after we restart the DB. However, this one page keep hitting the error above. This has never happened before. Any one can help?
what is the value of look.image.url(:thumb) before line 18 executes? That is where the error is thrown, and it is the only place I am seeing a +
I'd check your data, to see if the crash caused data loss somewhere, in particular, on the data needed for that method
Try out something like this .....
<div class="look_list">
<% collection.each do |look| %>
<div class="look_book" id="<%= look.content_id %>">
<% thumbnail_image = look.image.url(:thumb) unless look.processing? %>
<% thumbnail_image.nil? ? "/assets/processing_placeholder.gif" : (look.image.url(:thumb) + "?#{look.updated_at.to_i}") %>
<%= image_tag thumbnail_image ,:class=> "look_image", :size => "118x118" %>
</div>
<% end %>
</div>
Related
Hello I have a Rails application in production, and recently i started getting totally random errors on the loading of the show method of my "complaints" controller .
My "complaints" table has a one-to-one relationship with "interactions" table, you can create an interaction then create a complaint.
I display my data in a table on complaints#index, then I click on a row to get to complaints#show
I get this error :
ActionView::Template::Error (undefined method `[]' for nil:NilClass):
7: <div class="uk-width-expand#m">
8: <h1 class="uk-heading-primary">
9: <%# <%= link_to 'Retour à l\'interaction', interaction_path(#variables[:complaint].interaction, search: #params[:search]), class: 'uk-button uk-button-default uk-margin-right' %>
10: <%= I18n.t("kind.#{#variables[:complaint].kind}") %>
11: <% if #variables[:complaint].interaction.date.present? %>
12: - <%= #variables[:complaint].interaction.date.strftime('%d/%m/%Y') %>
13: <% end %>
app/views/complaints/show.html.erb:10:in `_app_views_complaints_show_html_erb__763547916_154685640'
But this error appears totaly randomly. That means if I refresh the page, it may launch this time. So because of this, i can't understand where this error comes from, most of the time there is no error, but I get complaints from the app users saying they are really bothered.
Here is my controller show method :
def show
complaint = Complaint.find_by(id: params[:id])
if complaint.blank?
redirect_to complaints_path
return
end
interaction = Interaction.find(complaint.interaction.id)
result = DetailCommande.execute_procedure "p_detail_commande", interaction.do_piece, interaction.do_type
contenu_commande = DetailCommande.execute_procedure "p_contenu_commande", interaction.do_piece, interaction.do_type
#variables = { complaint: complaint, detail_commande: result[0], contenu_commande: contenu_commande }
#params = { search: params[:search] }
end
Here is the part of my complaints#show view that causes trouble :
<div class="uk-flex-middle uk-margin-small" uk-grid>
<div class="uk-width-expand#m">
<h1 class="uk-heading-primary">
<%= link_to 'Retour à l\'interaction', interaction_path(id: params[:id], search: #params[:search]), class: 'uk-button uk-button-default uk-margin-right' %>
<%= I18n.t("kind.#{#variables[:complaint].kind}") %>
<% if #variables[:complaint].interaction.date.present? %>
- <%= #variables[:complaint].interaction.date.strftime('%d/%m/%Y') %>
<% end %>
</h1>
</div>
<div class="uk-width-auto#m">
<% if #variables[:complaint].control.present? %>
<button class="uk-button uk-button-default" disabled>Contrôle</button>
<% else %>
<a href="#modal-control-<%= params[:id] %>" class="uk-button uk-button-warning" uk-toggle>Contrôle</a>
<% end %>
<%= link_to 'Modifier', edit_complaint_path(id: #variables[:complaint].id, search: #params[:search]), class: 'uk-button uk-button-primary' %>
<%= link_to 'Supprimer', complaint_path(#variables[:complaint], search: #params[:search]), method: :delete, data: {confirm: 'Êtes-vous sûr ?'}, class: 'uk-button uk-button-danger' %>
</div>
</div>
And here is a screen of my page when it actually loads. Just simple data display
I don't know if i provided enough informations, but thank you in advance for your help
I think that your application is running on 2 servers , sharing the load by load balancer.
I think so because of the following 2 cases:
See line no. 9 of your log i.e.
9: <%# <%= link_to 'Retour à l\'interaction', interaction_path(#variables[:complaint].interaction, search: #params[:search]), class: 'uk-button uk-button-default uk-margin-right' %>
and your html file does not contains this code, this are some changes in show.html i.e.
<%= link_to 'Retour à l\'interaction', interaction_path(id: params[:id], search: #params[:search]), class: 'uk-button uk-button-default uk-margin-right' %>
This error gone on page refresh, it means that 1 server contains correct code and 1 contains wrong code, so when the request goes on server 1, it displays the page and when it goes on server2, it gives error.
As per the logs, I think that complaint.kind is empty.
I'm trying to implement new redmine and then migrate my data from old redmine to new redmine.
But there is an template error showing in the log
ActionView::Template::Error (undefined method `is_closed?' for nil:NilClass):
6: <h3><%= format_activity_day(day) %></h3>
7: <dl>
8: <% sort_activity_events(#events_by_day[day]).each do |e, in_group| -%>
9: <dt class="<%= e.event_type %> <%= "grouped" if in_group %> <%= User.current.logged? && e.respond_to?(:event_author) && User.current == e.event_author ? 'me' : nil %>">
10: <%= avatar(e.event_author, :size => "24") if e.respond_to?(:event_author) %>
11: <span class="time"><%= format_time(e.event_datetime, false) %></span>
12: <%= content_tag('span', h(e.project), :class => 'project') if #project.nil? || #project != e.project %>
app/models/issue.rb:677:in `closed?'
app/models/issue.rb:57:in `block in <class:Issue>'
I guess this monday is occured when the css is rendered.
Is there any idea about this problem?
or how to log and find the real cause of the problem?
Thanks
I want to make a fairly straightforward image link that uses an image from my assets. Getting weird errors. First I tried:
<%= link_to assets_path "town.png", 'index' %>
and got the error
Started GET "/" for 127.0.0.1 at Wed Nov 30 17:27:10 -0500 2011
Processing by PagesController#intro as HTML
Rendered pages/intro.html.erb within layouts/application (114.9ms)
Completed 500 Internal Server Error in 124ms
ActionView::Template::Error (undefined method `assets_path' for #<#<Class:0x10fdc4898>:0x10fdaad58>):
1: <body onload="init();">
2: <div id = "wrapper2">
3: <div class="intro_txt">
4: <%= link_to assets_path "town.png", 'index' %>
5: <br><br>
6: </div>
7: </div>
app/views/pages/intro.html.erb:4:in `_app_views_pages_intro_html_erb__1651075534_2280428740'
then I tried the old
<%= link_to image_tag "town.png", 'index' %>
and got this bizarre error
ActionView::Template::Error (undefined method `symbolize_keys!' for "index":String):
1: <body onload="init();">
2: <div id = "wrapper2">
3: <div class="intro_txt">
4: <%= link_to image_tag "townProjectText.png", 'index' %>
5: <br><br>
6: </div>
7: </div>
app/views/pages/intro.html.erb:4:in `_app_views_pages_intro_html_erb__1651075534_2279838600'
What to do?
<%= link_to image_tag('town.png'), 'index' %>
Put some parentheses
You need some ()
<%= link_to image_tag("town.png"), pages_path %>
Also, you need to use image_tag
<%= link_to image_tag("town.png"), image_path %>
if you want it to go to another page with the image by itself
Yeah some brackets would perhaps help. Try something like this:
<%= link_to(image_tag("town.png", :alt => 'Town Image'), index_url) %>
I've got the following code in my show.html.erb file:
<p>
<b>Status:</b>
<% if #server.serverUp?.to_s == "Up" %>
<% #server.update_attribute(#server.serverStatus, 'Up') %>
<span style="color: green;"> <%= #server.serverUp? %></span>
<% else %>
<span style="color: #ff0000;"> <%= #server.serverUp? %></span>
<% end %>
</p>
My main concerns is with the line <% #server.update_attribute(#server.serverStatus, 'Up') %> which breaks my app from working. This line is supposed to save the status of the Server, whether it is "Up" or "Down", and save it in 'servers' table under the 'serverStatus' column.
However, when I go to http://localhost:3000/servers/id_of_server, where 'id_of_server' is a number from 1-300, the following error message appears:
NoMethodError in Servers#show
Showing C:/SIS/app/views/servers/show.html.erb where line #18 raised:
undefined method `=' for #<Server:0x60b9358>
Extracted source (around line #18):
15: <p>
16: <b>Status:</b>
17: <% if #server.serverUp?.to_s == "Up" %>
18: <% #server.update_attribute(#server.serverStatus, 'Up') %>
19: <span style="color: green;"> <%= #server.serverUp? %></span>
20: <% else %>
21: <span style="color: #ff0000;"> <%= #server.serverUp? %></span>
I don't seem to understand the error message, as I haven't used an equal sign in the extract of code provided. Any help would be appreciated.
If you guys need any more info let me know.
Thanks in advance
Edit: While I'm at it, I just wanted to ask whether I'm not following the RoR conventions by putting that type of code into the show.html.erb file as opposed to somewhere else? Because in the same file I also have another algorithm which reads all the attributes of a model, puts it into an array, and displays only the unique values.
Thanks
You should write:
<% #server.update_attribute(:serverStatus, 'Up') %>
And yes: you should not update models in view. In your case it could cleanly live in a before_save or why not in an after_initialize callback in the model I guess.
Lastly: in Ruby, convention is snake case so server_status instead of serverStatus
I am using Rails 2.3.11 end the error is:
NoMethodError in Configurations#index
Showing rails/ruby/1.8/gems/actionpack-2.3.11/lib/action_controller/templates/rescues/diagnostics.erb where line #7 raised:
private method `gsub' called for nil:NilClass
Extracted source (around line #7):
4: in <%=h request.parameters['controller'].humanize %>Controller<% if request.parameters['action'] %>#<%=h request.parameters['action'] %><% end %>
5: <% end %>
6: </h1>
7: <pre><%=h #exception.clean_message %></pre>
8:
9: <%= render :file => #rescues_path["rescues/_trace.erb"] %>
10:
My feeling is that #exception is null, since no exceptions were raised on page.
Try something like:
<% if !#exception.nil? %>
<%=h #exception.clean_message %>
<% end %>