How do I use another controllers methods inside of another controllers views?
I have a Users controller and a Worlds controller each with their own model and views. I am trying to use something from the Worlds view within the Users views
<% @worlds.each do |world| %>
...
<% end %>
but I am getting "You have a nil o开发者_开发问答bject when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each"
this listing of each world works as expected when used within the Worlds views
Just define in your action in UsersController your @worlds
variabe:
# UsersController
def index
@worlds = World.all
end
And you should understand, that Models and Controllers are different essences. The are separated. Controller can use any model. Controller is a layer between all models and particular view.
精彩评论