Is there any easy way of using something like current_page? method from ActionView::Helpers::UrlHelper inside controller ? I have routing like: resources :addresses resources :mailing_addresses, :controller => ''addresses'' And I would like to do a check in my controller that would look like this: class AddressesController def index if current_page?(live_addresses_path) # ... logic goes here elsif current_page?(addresses_path) # ... logic goes here end end end What''s the easiest way of achieving it ? Robert Pankowecki -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Robert Pankowecki wrote:> Is there any easy way of using something like current_page? method > from ActionView::Helpers::UrlHelper inside controller ? > I have routing like: > resources :addresses > resources :mailing_addresses, :controller => ''addresses'' > > And I would like to do a check in my controller that would look like > this: > > class AddressesController > > def index > if current_page?(live_addresses_path) > # ... logic goes here > elsif current_page?(addresses_path) > # ... logic goes here > end > end > > end > > What''s the easiest way of achieving it ? > > Robert PankoweckiHi Robert, I think what you can check is params[:controller] and params[:action]. This would give you the current location in your app. Thanks, Anubhaw -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
resources :addresses resources :mailing_addresses, :controller => ''addresses'' <===== this is here confuses me, why not have another controller? this will generate 7 restful action to a controller that has already 7 restful action but anyway it should be like this in you routes :requirements => { :context_type => ''addresses''} and then in you controller check context_type == "addresses" On Fri, Sep 10, 2010 at 6:25 AM, Anubhaw Prakash <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Robert Pankowecki wrote: > > Is there any easy way of using something like current_page? method > > from ActionView::Helpers::UrlHelper inside controller ? > > I have routing like: > > resources :addresses > > resources :mailing_addresses, :controller => ''addresses'' > > > > And I would like to do a check in my controller that would look like > > this: > > > > class AddressesController > > > > def index > > if current_page?(live_addresses_path) > > # ... logic goes here > > elsif current_page?(addresses_path) > > # ... logic goes here > > end > > end > > > > end > > > > What''s the easiest way of achieving it ? > > > > Robert Pankowecki > > Hi Robert, > I think what you can check is params[:controller] and params[:action]. > This would give you the current location in your app. > > Thanks, > Anubhaw > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I have 3 different type of addresses fot person. I can create and display them using same views currently (but that might change in the future) so I created one controller which recognizes which kind of address you want to deal with now by checking the URL. In a moment when there is some benefit of maintaining them with separate controllers then I can change it without changing urls. Now going to /addresses shows all of them but going to / mailing_addresses or /registered_addresses shows only subtypes. It''s not so complicated to create another controller. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
did you solve your problem? On Fri, Sep 10, 2010 at 11:40 AM, Robert Pankowecki (rupert) < robert.pankowecki-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have 3 different type of addresses fot person. I can create and > display them using same views currently (but that might change in the > future) so I created one controller which recognizes which kind of > address you want to deal with now by checking the URL. In a moment > when there is some benefit of maintaining them with separate > controllers then I can change it without changing urls. > Now going to /addresses shows all of them but going to / > mailing_addresses or /registered_addresses shows only subtypes. It''s > not so complicated to create another controller. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Yes. It works ok with code that look something like that : request.fullpath.include?(mailing_addresses_path) Robert Pankowecki -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
with this :requirements => { :context_type => ''addresses''} and then in you controller check context_type == "addresses" its checked by the router instead of the controller On Sat, Sep 11, 2010 at 2:35 PM, Robert Pankowecki (rupert) < robert.pankowecki-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yes. It works ok with code that look something like that : > > request.fullpath.include?(mailing_addresses_path) > > Robert Pankowecki > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I still can''t understand your example. What''s up with this context_type ? Let''s say that I have 3 different kind of addresses. What should I put in routes.rb and what should I check in controller ? r. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
check out how to user requirement here http://railscasts.com/episodes/70-custom-routes On Sun, Sep 12, 2010 at 3:19 AM, Robert Pankowecki (rupert) < robert.pankowecki-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I still can''t understand your example. What''s up with this > context_type ? Let''s say that I have 3 different kind of addresses. > What should I put in routes.rb and what should I check in controller ? > > r. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I think I started to understand your idea. You want me to write my own custom routes for every action but in the place of URL where usually controller name is place put my own custom requirement ? like get "user/:user_id/:addres_type/" get "user/:user_id/:addres_type/new" get "user/:user_id/:addres_type/:id" get "user/:user_id/:addres_type/:id/edit" ? Robert Pankowecki -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
i think this king of manipulation is more clear and you dont need to declare one per resource route it works like this too resources :mailing_addresses, :controller => ''addresses'', :requirements => { :context_type => ''addresses''} then in the controller check for context_type like this if params[:context_type] == "addresses" you see is almost then same but less code the result is similar but part of the work is done by the router, and instead of checking the request object you check this On Sun, Sep 12, 2010 at 3:38 PM, Robert Pankowecki (rupert) < robert.pankowecki-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I think I started to understand your idea. You want me to write my own > custom routes for every action but in the place of URL where usually > controller name is place put my own custom requirement ? > > like > > get "user/:user_id/:addres_type/" > get "user/:user_id/:addres_type/new" > get "user/:user_id/:addres_type/:id" > get "user/:user_id/:addres_type/:id/edit" > > ? > > Robert Pankowecki > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.