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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---