I’ve got an index page where I’ve decided to render both Usernames, Posts and other informative sources.
Since Devise takes care of the user creations and login sessions-managing I am aware of needing to have multiple controllers.
PostsController, DashboardController and RandomController. The plan is to make them be rendered on different parts of the page, with different sizes and on different places.
Let’s say I’ve got Post.find(:all => :order => "created_at DESC") in the PostsController. I want to render that someplace on the page.
I want to render Usernames right under the according Post which belongs_to them, and I want to render some still “Random” Controller action which will post news on some random place on the page.
So a recap:
The PostsController finds and renders some part of the index page, and the DeviseControllers I guess renders the username belonging to the according one, and the Random Controller renders some random thing from news or something on the middle of the page. Amongst all of them all of this is happening on another controller called DashBoard.
So all these controller actions are supposed to be rendered on a own DashBoard controller index view.
Any tips, or good ideas on how to accomplish this. I know about partial rendering, but I don’t know how to achieve that.
It seems we’re talking about a view rendered by Dashboard#index. So all you need to do is define all the info on the page as instance variables under the index action.
Probably the bit of info that’s missing for you is that controllers are free to use data from any of your models (and even other classes that don’t inherit from ActiveRecord::Base).
For instance, in Dashboard#index, you can have:
Which is referring to a different model than the Dashboard model (assuming one exists).