I''m trying to add paging parameters to link_to inside an application_helper method. def index_show_link(elm, link_text = ''Show'') (can?(:read, elm)) ? link_to( link_text, elm ) : '' ''.html_safe end I want to add the :page => params[:page] pair into the link, but I can''t seem to find a way to add it. If I use the long-hand syntax: {:id => elm.id, :controller => controller_name, :action => :show, :page => params[:page]} then it works, but that also horses around with friendly_id. I''ve looked through the link_to and url_for documentation, and I can''t see a way to pass the bare object to either method and also include the extra parameter. What''s the trick? Thanks, Walter -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Oct 5, 2011, at 3:48 PM, Walter Lee Davis wrote:> I''m trying to add paging parameters to link_to inside an application_helper method. > > def index_show_link(elm, link_text = ''Show'') > (can?(:read, elm)) ? link_to( link_text, elm ) : '' ''.html_safe > end > > I want to add the :page => params[:page] pair into the link, but I can''t seem to find a way to add it. If I use the long-hand syntax: {:id => elm.id, :controller => controller_name, :action => :show, :page => params[:page]} then it works, but that also horses around with friendly_id.I found that substituting to_param for id makes FriendlyId work correctly again, and this one is solved. Still seems awfully long-hand. Walter -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Oct 6, 1:32 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> On Oct 5, 2011, at 3:48 PM, Walter Lee Davis wrote: > > > I''m trying to add paging parameters to link_to inside an application_helper method. > > > def index_show_link(elm, link_text = ''Show'') > > (can?(:read, elm)) ? link_to( link_text, elm ) : '' ''.html_safe > > end > > > I want to add the :page => params[:page] pair into the link, but I can''t seem to find a way to add it. If I use the long-hand syntax: {:id => elm.id, :controller => controller_name, :action => :show, :page => params[:page]} then it works, but that also horses around with friendly_id. > > I found that substituting to_param for id makes FriendlyId work correctly again, and this one is solved. Still seems awfully long-hand. >link_to ''text'', blah is a more convenient way of writing link_to ''text'', polymorphic_path(blah) or link_to ''text'', blah_path(blah) (assuming you have resources :blahs). Both of those two _path helpers should allow you to specify extra options (i.e. polymorphic_path(blah, :page => 2)) Fred> Walter-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Oct 6, 2011, at 10:27 AM, Frederick Cheung wrote:> > > On Oct 6, 1:32 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: >> On Oct 5, 2011, at 3:48 PM, Walter Lee Davis wrote: >> >>> I''m trying to add paging parameters to link_to inside an application_helper method. >> >>> def index_show_link(elm, link_text = ''Show'') >>> (can?(:read, elm)) ? link_to( link_text, elm ) : '' ''.html_safe >>> end >> >>> I want to add the :page => params[:page] pair into the link, but I can''t seem to find a way to add it. If I use the long-hand syntax: {:id => elm.id, :controller => controller_name, :action => :show, :page => params[:page]} then it works, but that also horses around with friendly_id. >> >> I found that substituting to_param for id makes FriendlyId work correctly again, and this one is solved. Still seems awfully long-hand. >> > > link_to ''text'', blah > > is a more convenient way of writing link_to ''text'', > polymorphic_path(blah) or link_to ''text'', blah_path(blah) (assuming > you have resources :blahs). > Both of those two _path helpers should allow you to specify extra > options (i.e. polymorphic_path(blah, :page => 2))So are you saying that if I''m in the application helper, I can use a polymorphic_path, even though I am not declaring anything to be polymorphic? That''s a new one on me. Walter> > Fred >> Walter > > -- > 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@googlegroups.com. > 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Oct 6, 2011, at 11:59 AM, Walter Lee Davis wrote:> > On Oct 6, 2011, at 10:27 AM, Frederick Cheung wrote: > >> >> >> On Oct 6, 1:32 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: >>> On Oct 5, 2011, at 3:48 PM, Walter Lee Davis wrote: >>> >>>> I''m trying to add paging parameters to link_to inside an application_helper method. >>> >>>> def index_show_link(elm, link_text = ''Show'') >>>> (can?(:read, elm)) ? link_to( link_text, elm ) : '' ''.html_safe >>>> end >>> >>>> I want to add the :page => params[:page] pair into the link, but I can''t seem to find a way to add it. If I use the long-hand syntax: {:id => elm.id, :controller => controller_name, :action => :show, :page => params[:page]} then it works, but that also horses around with friendly_id. >>> >>> I found that substituting to_param for id makes FriendlyId work correctly again, and this one is solved. Still seems awfully long-hand. >>> >> >> link_to ''text'', blah >> >> is a more convenient way of writing link_to ''text'', >> polymorphic_path(blah) or link_to ''text'', blah_path(blah) (assuming >> you have resources :blahs). >> Both of those two _path helpers should allow you to specify extra >> options (i.e. polymorphic_path(blah, :page => 2)) > > So are you saying that if I''m in the application helper, I can use a polymorphic_path, even though I am not declaring anything to be polymorphic? That''s a new one on me.Refactored, works great! Thanks! Walter> > Walter > >> >> Fred >>> Walter >> >> -- >> 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. >> > > -- > 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@googlegroups.com. > 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Oct 6, 5:09 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> On Oct 6, 2011, at 11:59 AM, Walter Lee Davis wrote:> >> is a more convenient way of writing link_to ''text'', > >> polymorphic_path(blah) or link_to ''text'', blah_path(blah) (assuming > >> you have resources :blahs). > >> Both of those two _path helpers should allow you to specify extra > >> options (i.e. polymorphic_path(blah, :page => 2)) > > > So are you saying that if I''m in the application helper, I can use a polymorphic_path, even though I am not declaring anything to be polymorphic? That''s a new one on me. > > Refactored, works great! Thanks!polymorphic_path is a rails provided method - it''s what gets called by rails when you shorthand stuff like form_for(some_object) or link_to ''blah'', some_other_object. It basically just looks at the class name (probably via the activemodel::naming) stuff and then calls the explicit path helper (comment_path etc) that it expects to exist given what you''re asking it to do. Fred -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.