问题
Possible Duplicate:
MetaSearch “undefined method `model_name' for NilClass:Class” for global bar search
This is the error I'm getting using my updated code when I try going to a user's profile or a individual posts (/posts/1). Its weird that its trying to access the unlike partial anyway because its a new user without any likes.
I've got the code exactly as it shows in the tutorial I used to do this with following users. It works fine for users following users, but I've set it up trying to do with users liking posts.
ActionView::Template::Error (undefined method `model_name' for NilClass:Class):
1: <%= form_for(current_user.appreciations.find_by_liked_id(@user),
2: :html => { :method => :delete },
3: :remote => true) do |f| %>
4: <div class="actions"><%= f.submit "Unlike" %></div>
app/views/users/_unlike.html.erb:1:in `_app_views_users__unlike_html_erb___769256097635878617_2160255900__1293121959744503098'
app/views/users/_like_form.html.erb:6:in `_app_views_users__like_form_html_erb___3308190581058867471_2162903180_52867338942162503'
app/views/posts/show.html.erb:7:in `_app_views_posts_show_html_erb___3188789470217885182_2183453320__3624460432667345580'
Here's the pastie with just about everything, if I missed something just let me know. I really appreciate the insight to get this working.
http://pastie.org/1824955
回答1:
Nothing assigns a value to the @post
variable. You have not posted the code for the view(s) that include(s) any of the partials above, but I assume you are iterating over the posts in @posts
, probably assigning each one to a local variable called post
. You should presumably be passing that post
variable to the partial as a local ..., :locals => {:post => post}
, and then referring to post
, not @post
within the partials.
来源:https://stackoverflow.com/questions/5755887/rails-actionviewtemplateerror-undefined-method-model-name-for-nilclassc