views:

88

answers:

2

I currently have one model, one controller with one action to list all the items in the model.

What I need to do is display different data from the model in two separate views. Is there a way I can use one controller action to display different views based on params, or should I create another action?

The reason why I hesitate to create another action is because I'll have to essentially duplicate all the routing I setup for the previous action.

Thanks for any ideas.

+3  A: 

I'm not entirely sure that you've provided enough information to give what could be considered a 'good' answer, but if I'm understanding you correctly, this should be possible.

For example, couldn't you do something like this?

def show
  @my_objects = MyObject.all

  if params[:full_view]
    render :action => 'show_full_fiew' and return
  end

  # if you get here, it will render the 'show' action
end

Let me know if that helps. If you could give some more information, I might be able to clean up this example to be a bit more informative.

jerhinesmith
This does help, I wasn't aware of sending one action to another. Would it be possible to just show different views based on the params?
coasthird
A: 

You don't mention if you're using resource routes or not. If so, I'd just add a new option to your routes.

map.resources :products, :collection => { :some_great_name => :get }

You really shouldn't worry about adding views or new actions to your controller. An action should usually only have a few lines of code. If your controller actions start to grow in complexity you should think about moving that logic into your model.

Andy Gaskell