Hello, I''m trying to implement Rails functionality which would allow to compare Model records (in my case different plans). I''m unsure what would be the proper approach towards this with Rails, is there any tutorial for doing something like available on internet/book? Which would be better: to pass the comparing model ids to the compare controller by post or by url? Any tips are highly appreciated. -- Posted via http://www.ruby-forum.com/.
2009/11/8 Aljaz Fajmut <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Hello, > > I''m trying to implement Rails functionality which would allow to compare > Model records (in my case different plans). > > I''m unsure what would be the proper approach towards this with Rails, is > there any tutorial for doing something like available on internet/book? > > Which would be better: to pass the comparing model ids to the compare > controller by post or by url? > > Any tips are highly appreciated. > --If I understand correctly you have records in the db and wish to compare them on demand by the user clicking on a link which goes to a compare controller. In this case I would pass the id values as parameters of a GET request on the compare controller. It should not be a POST as it does not cause the data in the db to be changed. The actual compare operation should be a method of the model whose objects are being compared of course. Colin
How can you pass array of parameters to GET request? Colin Law wrote:> 2009/11/8 Aljaz Fajmut <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: >> controller by post or by url? >> >> Any tips are highly appreciated. >> -- > > If I understand correctly you have records in the db and wish to > compare them on demand by the user clicking on a link which goes to a > compare controller. In this case I would pass the id values as > parameters of a GET request on the compare controller. It should not > be a POST as it does not cause the data in the db to be changed. The > actual compare operation should be a method of the model whose objects > are being compared of course. > > Colin-- Posted via http://www.ruby-forum.com/.
2009/11/8 Aljaz Fajmut <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > How can you pass array of parameters to GET request?The same as anything else, eg if @my_array contains [0,1,2] <%= link_to ''Compare'', :controller => ''compare'', :action => ''do_compare'', :ids => @my_array %> If the values you want to pass come from fields then it just a matter of setting up the fields correctly. Google should be able to sort you out, I always have to look it up. If you are only comparing two records then just pass the ids as two params. Colin> > > Colin Law wrote: >> 2009/11/8 Aljaz Fajmut <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: >>> controller by post or by url? >>> >>> Any tips are highly appreciated. >>> -- >> >> If I understand correctly you have records in the db and wish to >> compare them on demand by the user clicking on a link which goes to a >> compare controller. In this case I would pass the id values as >> parameters of a GET request on the compare controller. It should not >> be a POST as it does not cause the data in the db to be changed. The >> actual compare operation should be a method of the model whose objects >> are being compared of course. >> >> Colin > > -- > Posted via http://www.ruby-forum.com/. > > > >
I would do it with nested routes and map.resource. You would end up with a rout that looked like this: /plans/:plan_id/compare/:id If you are comparing more than one at a time then I would do what was suggested before and pass an array of IDs as a GET request. On Nov 8, 8:31 am, Aljaz Fajmut <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hello, > > I''m trying to implement Rails functionality which would allow to compare > Model records (in my case different plans). > > I''m unsure what would be the proper approach towards this with Rails, is > there any tutorial for doing something like available on internet/book? > > Which would be better: to pass the comparing model ids to the compare > controller by post or by url? > > Any tips are highly appreciated. > -- > Posted viahttp://www.ruby-forum.com/.
Colin Law wrote:> 2009/11/8 Aljaz Fajmut <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: >> >> How can you pass array of parameters to GET request? > > The same as anything else, eg > if @my_array contains [0,1,2] > <%= link_to ''Compare'', :controller => ''compare'', :action => > ''do_compare'', :ids => @my_array %> > > If the values you want to pass come from fields then it just a matter > of setting up the fields correctly. Google should be able to sort you > out, I always have to look it up. > > If you are only comparing two records then just pass the ids as two > params. > > ColinWould it make more sense to make separate controller for comparations or would it be better to place it inside Plans controller? Thanks again! -- Posted via http://www.ruby-forum.com/.
2009/11/8 Aljaz Fajmut <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > > Would it make more sense to make separate controller for comparations or > would it be better to place it inside Plans controller?Whichever makes more sense for you is the way to go. I think I would probably put it in a compare action in the Plans controller. Colin