Hello, How do I get params from a form to use with a paginator? debug(params) shows this city: !map:HashWithIndifferentAccess id: "1" but in my controller, when I try to use @hotel_pages = Paginator.new self, Hotel.count(:conditions => "hotels.city_id = params[:city][:id]"), 3, @params[''page''] it doesn''t work. I suppose it''s a simple syntax error but have no idea to fix it. Thanks for your help! -- Posted via http://www.ruby-forum.com/.
> @hotel_pages = Paginator.new self, Hotel.count(:conditions => > "hotels.city_id = params[:city][:id]"), 3, @params[''page'']@hotel_pages, @hotels = paginate(:hotels, :conditions => ["hotels.city_id = ?", params[:city][:id]], :per_page => 3, :page => @params[''page'']) Try something like that. -- Posted via http://www.ruby-forum.com/.
> but in my controller, when I try to use > @hotel_pages = Paginator.new self, Hotel.count(:conditions => > "hotels.city_id = params[:city][:id]"), 3, @params[''page''] > > it doesn''t work. I suppose it''s a simple syntax error but have no idea > to fix it.Nobody? -- Posted via http://www.ruby-forum.com/.
> but in my controller, when I try to use > @hotel_pages = Paginator.new self, Hotel.count(:conditions => > "hotels.city_id = params[:city][:id]"), 3, @params[''page'']Nobody? -- Posted via http://www.ruby-forum.com/.
> @hotel_pages, @hotels = paginate(:hotels, :conditions => > ["hotels.city_id = ?", params[:city][:id]], :per_page => 3, :page => > @params[''page'']) > > Try something like that.Thanks Dr Nic, I replaced :page => @params[''page''] by :parameter => ''page'' and it works but only for the first page, then I have an error You might have expected an instance of Array. The error occured while evaluating nil.[] Any idea? -- Posted via http://www.ruby-forum.com/.
> Thanks Dr Nic, I replaced :page => @params[''page''] by :parameter => > ''page'' and it works but only for the first page, then I have an error > You might have expected an instance of Array. > The error occured while evaluating nil.[]Try :parameter => params[:page] -- Posted via http://www.ruby-forum.com/.
> Try :parameter => params[:page]In fact, I think it''s more a hash problem in the link previous / next. I found that in the archives: "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]) So the question is: is it the only way to add an hash in a link? -- Posted via http://www.ruby-forum.com/.