开发者

using one controllers actions within another controllers views

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜