Hey I need some help with pagination and the link_to in the view. I''m trying to include a hash in the pagination link_to params and it keeps flattening out my hash. Example: Here''s my hash called @answer: "answer"=>{"6"=>"9bf31c7ff062936a96d3c8bd1f8f2ff3", "7"=>"6f4922f45568161a8cdf4ad2299f6d23"} Here''s the code in my view for my pagination link: <%= link_to(''next'', {:params => params.merge(''answer'' => @answer, ''page'' => object_pages.current.previous,)}) + '' '' if object_pages.current.previous %> See how the link_to doesn''t maintain the actual hash: <a href="/student_portal/evaluate_exam/7?commit=Submit+Test& answer=69bf31c7ff062936a96d3c8bd1f8f2ff376f4922f45568161a8cdf4ad2299f6d23&page=2">next</a> Anyone know how I can pass a hash intact through a link_to ? Thanks a ton! Chris
On Jun 7, 2006, at 3:55 AM, chris landry wrote:> Hey > > I need some help with pagination and the link_to in the view. > > I''m trying to include a hash in the pagination link_to params and it > keeps flattening out my hash. > > Example: > Here''s my hash called @answer: > "answer"=>{"6"=>"9bf31c7ff062936a96d3c8bd1f8f2ff3", > "7"=>"6f4922f45568161a8cdf4ad2299f6d23"} > > Here''s the code in my view for my pagination link: > <%= link_to(''next'', {:params => params.merge(''answer'' => @answer, > ''page'' => object_pages.current.previous,)}) + '' '' if > object_pages.current.previous %> > > See how the link_to doesn''t maintain the actual hash: > <a href="/student_portal/evaluate_exam/7?commit=Submit+Test& > > answer=69bf31c7ff062936a96d3c8bd1f8f2ff376f4922f45568161a8cdf4ad2299f6 > d23&page=2">next</a> > > Anyone know how I can pass a hash intact through a link_to ? > > Thanks a ton! > Chris > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/railsHey Chris- To get a hash through in an url like that you need to serialize it and deserialize it. Something like this: #in your application controller somewhere: require ''base64'' def construct_for_link(object) Base64.encode64(Marshal.dump(object)) end helper_method : construct_for_link def deconstruct_from_link(object) Marshal.load(Base64.decode64(object)) end helper_method :deconstruct_from_link # then in your view <%= link_to(''next'', {:params => params.merge(''answer'' => construct_for_link(@answer), ''page'' => object_pages.current.previous,)}) + '' '' if object_pages.current.previous %> # in controller answer = deconstruct_from_link(params[:answer]) Cheers- -Ezra
Julian ''Julik'' Tarkhanov
2006-Jun-07 19:15 UTC
[Rails] Hash flattening on paginator link_to
On 7-jun-2006, at 19:02, Ezra Zygmuntowicz wrote:> > On Jun 7, 2006, at 3:55 AM, chris landry wrote: > >> Hey >> >> I need some help with pagination and the link_to in the view. >> >> I''m trying to include a hash in the pagination link_to params and it >> keeps flattening out my hash. >> >> Example: >> Here''s my hash called @answer: >> "answer"=>{"6"=>"9bf31c7ff062936a96d3c8bd1f8f2ff3", >> "7"=>"6f4922f45568161a8cdf4ad2299f6d23"} >> >> Here''s the code in my view for my pagination link: >> <%= link_to(''next'', {:params => params.merge(''answer'' => @answer, >> ''page'' => object_pages.current.previous,)}) + '' '' if >> object_pages.current.previous %> >> >> See how the link_to doesn''t maintain the actual hash: >> <a href="/student_portal/evaluate_exam/7?commit=Submit+Test& >> >> answer=69bf31c7ff062936a96d3c8bd1f8f2ff376f4922f45568161a8cdf4ad2299f >> 6d23&page=2">next</a> >> >> Anyone know how I can pass a hash intact through a link_to ?or just http://dev.rubyonrails.org/ticket/4947 -- Julian ''Julik'' Tarkhanov please send all personal mail to me at julik.nl