Undefined method link_to_remote error Rails - ruby-on-rails

I make a link_to_remote but this are the error:
NoMethodError in Tasks#index
Showing /Users/overallduka/youimports_app/app/views/tasks/index.html.erb where line #6 raised:
undefined method `link_to_remote' for #<#<Class:0x1022c76f0>:0x10216ff00>
Extracted source (around line #6):
3: <div id="all_tasks">
4: <% #tasks.each do |task| %>
5: <%= task.title %><br />
6: <p class="about_task"><%= link_to_remote task.status,"alert('aaa')" %> <%= task.about %></p>
7: <% end %>
8: </div>
I dont know what is wrong i make a sample alert to test but the error persistes, i dont know what is wrong in my view are:
NoMethodError in Tasks#index
Showing /Users/overallduka/youimports_app/app/views/tasks/index.html.erb where line #6 raised:
undefined method `link_to_remote' for #<#:0x10216ff00>
Extracted source (around line #6):
<% #tasks.each do |task| %>
<%= task.title %><br />
<p class="about_task"><%= link_to_remote (status(task.status)),"alert('aaa')" %> <%= task.about %></p>
<% end %>

link_to_remote and other remote ajax helpers have been removed in rails 3 and moved to a gem https://github.com/rails/prototype_legacy_helper. if you are only trying to run a simple js after clicking a link, use link_to_function instead
link_to_function 'test_alert', 'alert("test")'

Related

ActionView::Template::Error (undefined method `+' for nil:NilClass):

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>

NoMethodError in one of my models #show actions

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

Problem application Rails 2 using bundler

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 %>

need help with acts_as_ferret and will_paginate to play nice together

I have installed will_paginate and acts_as_ferret on my system for ruby rails.
My paginate seems to work fine before installing acts_as_ferret. When I put in the code to do searching I get the following error:
NoMethodError in Community#search
Showing app/views/community/_result_summary.rhtml where line #3 raised:
undefined method `total_entries' for []:Array
Extracted source (around line #3):
1: <% if #users %>
2: <p>
3: Found <%= pluralize(#users.total_entries, "match") %>.
4: </p>
5: <% end %>
If I take out the search function, paginate works but it's pointless because I can't do searches. Can any one help me out on this one??
Thanks!!
Stephen
undefined method `total_entries' for []:Array
eror itself shows that you are calling total_entries method which is not array method.
you get more than one user in your #users.
try
1: <% unless #users.blank? %>
2: <p>
3: Found <%= pluralize(#users[0].total_entries, "match") %>.
4: </p>
5: <% end %>
EDITED
TRY
1: <% unless #users.blank? %>
2: <p>
3: Found <%= pluralize(#users.length, "match") %>.
4: </p>
5: <% end %>

Rails pagination error

I'm using the will_paginate plugin and I get the following error only when I'm running on a server rather than locally:
undefined method `total_pages' for []:Array
Extracted source (around line #8):
5: <% session[:page] = params[:page] %>
6: <h2>Previous Scenario</h2>
7: <% end %>
8: <%= will_paginate #scenarios, :next_label => 'Older', :prev_label => 'Newer' %>
9: <div class="box">
10: <% for scenario in #scenarios %>
11: <% #created = scenario.created_at %>
Any ideas?
Somehow, #scenarios is an ordinary Array for you and it can't be from Scenario.paginate() method because that one always returns a WillPaginate::Collection object.
Does your controller have the other half of the equation, e.g.
#scenario = Scenario.paginate(:page => params[:page]||1)
Alternatively I think you might have a plugin on the server side that is converting your Active Record set into a plain array. I'd need a bit more info to look at that.

Resources