问题
I'm using this gem - TMDb - to build a simple app.
When I visit this URL i get the error:
.../movies/97857/movie_reviews/new
Form:
<%= form_for @movie do |movie_form| %>
<%= fields_for :movie_review, @movie.movie_review do |movie_review_fields| %>
Title : <%= movie_review_fields.text_field :title %>
<% end %>
<%= f.submit %>
<% end %>
Source code
回答1:
form_for expects an ActiveRecord
object (which has an instance method called model_name
). @movie
is a non-ActiveRecord object that comes from the gem you're using and it doesn't have a method called model_name
. That's why you get the error.
I see that you also have a Movie
model, but that is not what is used here. From your controller:
@movie = Tmdb::Movie.detail(params[:movie_id])
Since I don't know what you're trying to achieve, I can only point out why you get the error.
来源:https://stackoverflow.com/questions/21692437/undefined-method-model-name-for-tmdbmovieclass