Hi. I swear I found this in the group archives, but now I cannot find this in the group or elsewhere online! In a view I would like to get the current controller name and action that was used to get here. For example, I have a template that I''m using from two different controllers (and four different actions in each controller), such as :controller => "my_view", :action => "current" (or "expired", or "fixed", etc.) In this template I''m constructing some links to specific parameter calls of this same template, and I need to know which controller was used and what action was called to get us here. I thought it was something like this: link_to "This Year", :controller => @controller.name, :action => @controller.action The only thing I''ve found in the api that looks remotely similar is UrlHelper''s current_page(), but that''s not quite what I''m after, as I don''t want to test something, I just WANT that something :) Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Here is a link to what I think you are looking for http://www.postal-code.com/mrhappy/blog/2007/01/18/rails-knowing-the-current-action-in-a-view/ Good luck. On May 10, 11:22 pm, michael_teter <michael.te...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi. > > I swear I found this in the group archives, but now I cannot find this > in the group or elsewhere online! > > In a view I would like to get the current controller name and action > that was used to get here. > > For example, I have a template that I''m using from two different > controllers (and four different actions in each controller), such > as :controller => "my_view", :action => "current" (or "expired", or > "fixed", etc.) > > In this template I''m constructing some links to specific parameter > calls of this same template, and I need to know which controller was > used and what action was called to get us here. I thought it was > something like this: > > link_to "This Year", :controller => @controller.name, :action => > @controller.action > > The only thing I''ve found in the api that looks remotely similar is > UrlHelper''s current_page(), but that''s not quite what I''m after, as I > don''t want to test something, I just WANT that something :) > > Thanks.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> In a view I would like to get the current controller name and action > that was used to get here.params[:controller] params[:action]> In this template I''m constructing some links to specific parameter > calls of this same template, and I need to know which controller was > used and what action was called to get us here. I thought it was > something like this: > > link_to "This Year", :controller => @controller.name, :action => > @controller.actionUse url_for (or a named route), then _don''t_ pass the controller in. Url_for will find the controller in params if you don''t pass it in. (Write tests for all this stuff, using assert_xpath, to detect you are getting the links you expect!) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Excellent, thanks! I also just found this: http://snippets.dzone.com/posts/show/4391 <%= controller.controller_name %> <%= controller.action_name %> On May 11, 12:39 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > In a view I would like to get the current controller name and action > > that was used to get here. > > params[:controller] > params[:action] > > > In this template I''m constructing some links to specific parameter > > calls of this same template, and I need to know which controller was > > used and what action was called to get us here. I thought it was > > something like this: > > > link_to "This Year", :controller => @controller.name, :action => > > @controller.action > > Use url_for (or a named route), then _don''t_ pass the controller in. Url_for > will find the controller in params if you don''t pass it in. > > (Write tests for all this stuff, using assert_xpath, to detect you are getting > the links you expect!)--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---