Hi all, Please, is it possible passing a local variable (specifically of type "integer") from a view to controller using the "link_to" function in rails. All answers are appreciated. -- 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.
On Tue, Mar 9, 2010 at 10:22 AM, kevid <alumsimportant-FFYn/CNdgSA@public.gmane.org> wrote:> Please, is it possible passing a local variable (specifically of type > "integer") from a view to controller using the "link_to" function > in rails. > > All answers are appreciated.Have you read the API doc for link_to ? Your answer is there :-) (though HTTP request parameters are going to be strings, always) -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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.
thanks, pls can you post the link? On Mar 9, 7:30 pm, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Tue, Mar 9, 2010 at 10:22 AM, kevid <alumsimport...-FFYn/CNdgSA@public.gmane.org> wrote: > > Please, is it possible passing a local variable (specifically of type > > "integer") from a view to controller using the "link_to" function > > in rails. > > > All answers are appreciated. > > Have you read the API doc for link_to ? Your answer is there :-) > > (though HTTP request parameters are going to be strings, always) > > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassan-- 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.
kevid wrote:> pls can you post the link?http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M001597> Please, is it possible passing a local variable (specifically of type > "integer") from a view to controller using the "link_to" functionAlthough, this is not passing a local variable from the view to the controller. The link_to helper will generate a new request/response cycle. Any context you had will be lost, which is why your value must be passed as either part of the query string or as form data. Example from the above doc reference: link_to "Nonsense search", searches_path(:foo => "bar", :baz => "quux") # => <a href="/searches?foo=bar&baz=quux">Nonsense search</a> As noted by Hassan when you read your value from the params hash it will be a string. Use params[:my_value].to_i to get your FixNum value from inside your controller action. -- 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.
request parameters are always strings. You can convert string parameter to integer in controller using *to_i*method. On Wed, Mar 10, 2010 at 1:16 AM, Robert Walker <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> kevid wrote: > > pls can you post the link? > > > http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M001597 > > > Please, is it possible passing a local variable (specifically of type > > "integer") from a view to controller using the "link_to" function > > Although, this is not passing a local variable from the view to the > controller. The link_to helper will generate a new request/response > cycle. Any context you had will be lost, which is why your value must be > passed as either part of the query string or as form data. > > Example from the above doc reference: > > link_to "Nonsense search", searches_path(:foo => "bar", :baz => > "quux") > # => <a href="/searches?foo=bar&baz=quux">Nonsense search</a> > > As noted by Hassan when you read your value from the params hash it will > be a string. Use params[:my_value].to_i to get your FixNum value from > inside your controller action. > -- > 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. > >-- Sandip --- www.funonrails.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.