undefined method `model_name' for Tmdb::Movie:Class

风格不统一 提交于 2019-12-13 05:14:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!