Search code examples
ruby-on-railstemplatesrjs

problem with link_to_remote in Rails 2.1


I am facing this strange problem with the following section of code

<% if (@more == -1) %>
  <%= link_to_remote "More Posts", :html => {:id => 'more-link', :onClick => 'return false;'}%>
<% else %>
  <%= link_to_remote "More Posts", :url => {:action => 'view' ,:id => @more.to_i + 1} , :html => {:id => 'more-link'} %>
<% end %>

Now when I use this code, I get the following error

You have a nil object when you didn't expect it!You might have expected an instance of ActiveRecord::Base.The error occurred while evaluating nil.[]

Also the error seems to be at this line.

  <%= link_to_remote "More Posts", :html => {:id => 'more-link', :onClick => 'return false;'}%>

So cant really figure out why this is not working?


Solution

  • on line 4, look at

    'view' ,:id
    

    (move your comma over) also I'm thinking you would need a :url hash on line 2 as well