MVC .... Many views and one controller

What's the right RoR way if a controller needs to display one of many views in, say, an index method?

Ralph Shnelvar wrote:

What's the right RoR way if a controller needs to display one of many views in, say, an index method?

You can use render or redirect_to. But why would an index method need this?

Best,

Do you mean you want several different views all of which are 'index' views but arranged differently? If so then one method is to pass parameters to the index action via the url to determine which data and view to show.

Colin

For each controller in the line,

it’s defined methods be actions

for the implicit render of the view

with the names that match def and view,

If you write this way, you’ll save some typing

If you practice everyday, you may find a better way.

If you want to write about a Resource, it helps

to think about and read into REST.

It makes most sense when you have a noun.

non-rest Controller

BakeriesController

host:port/bakeries/index

host:port/bakeries/by_city

host:port/bakeries/that_have_nice_scones

REST resource PicklesController

host:port/pickles/index/

host:port/pickles/show/1

I would second Colin's suggestion.

Basically, you use some clue (URL parameter, session, database state or any external data) to decide what to render at the moment. If I needed such a thing, my approach would be to have several index partials or templates that I would render selectively. The naming would be _index_standard.xyz, _index_specific_1.xyz or something along these lines. Obviously, I wouldn't put the selection logic in the view itself.

- Aleksey