Rails way of selecting a partial with clean url?

hi,

in one of my views, i have some links, and depending on the value i set
in a variable, that chooses what partial i display.

for example in my view

link to “get all”, :action view, :id => something1, :switchOn =>
‘maincategory’

link to “get all”, :action view, :id => something2, :switchOn =>
‘subcategory’

controller

def view
if params[:switchOn] == ‘maincategory’
Bbq.find(:all)
@switchOn = ‘main’
end
if params[:switchOn] == ‘subcategory’
Bbq.find(:all, :condtion … something)
@switchOn = ‘sub’
end
end

view.rhtml
if @switchOn == ‘main’
render partial ‘viewmain’
end
if @switchOn == ‘sub’
render partial ‘viewsub’
end

doing this way, my url is kind of ugly. do i just rewrite or customize
my routes.rb?

thanks

One way I could think of is, you can render partials in the controller
itself.

def view
if params[:switchOn] == ‘maincategory’
Bbq.find(:all)
@switchOn = ‘main’
render :partial => ‘viewmain’
end
if params[:switchOn] == ‘subcategory’
Bbq.find(:all, :condtion … something)
@switchOn = ‘sub’
render :partial => ‘viewsub’
end
end

i can still do it that way, but i still get a funky url…

i wonder if there is a way to know what action triggered the call to
view from the link_to other than passing a param.

Kiran Soumya wrote:

One way I could think of is, you can render partials in the controller
itself.

def view
if params[:switchOn] == ‘maincategory’
Bbq.find(:all)
@switchOn = ‘main’
render :partial => ‘viewmain’
end
if params[:switchOn] == ‘subcategory’
Bbq.find(:all, :condtion … something)
@switchOn = ‘sub’
render :partial => ‘viewsub’
end
end

link to “get all”, :action view, :id => something1, :switchOn =>
‘maincategory’

link to “get all”, :action view, :id => something2, :switchOn =>
‘subcategory’

if your call looks like:

<%= link_to “get_all”, :url => { :action => :view, :id => foo, :switchOn
=> ‘subcategory’ } %>

then the “switchOn” param will be encoded into the URL, whereas if you
pull the param out, like:

<%= link_to “get_all”, :url => { :action => :view}, :id => foo,
:switchOn => ‘subcategory’ %>

then the url should look more like

get_all/actionview?id=1;switchOn=subcategory

which is a little nicer to read I think.