Hey, If i have a function in my model: def mark_sold self.update_attribute(:market_status, ''sold'') end Is it possible for this to be called via an on page link? Then I''d like to ajax it so a user could just scroll down a list clicking all links to "mark as sold" as he comes across old inventory. Thanks, brianp -- 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.
Quoting brianp <brian.o.pearce-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> Hey, > > If i have a function in my model: > def mark_sold > self.update_attribute(:market_status, ''sold'') > end > > Is it possible for this to be called via an on page link? > > Then I''d like to ajax it so a user could just scroll down a list > clicking all links to "mark as sold" as he comes across old inventory. >Browser requests always are to controller methods. Any other way you are fighting Rails'' MVC opinioned structure. Add a method to a controller and the route to config/routes.rb: def mark_sold model = Model.find(params[:id]) model.mark_sold render :partial => ..., :object => model end The render should generate the HTML for the changed model instance that the AJAX will replace. HTH, Jeffrey -- 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 Jeffrey, I had a good feeling this is how it needed to be done. But felt like I was bloating my controller. Now I''m happy knowing I was originally going in the right direction. Thanks again. brianp On Jan 27, 2:10 am, "Jeffrey L. Taylor" <r...-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> wrote:> Quoting brianp <brian.o.pea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > Hey, > > > If i have a function in my model: > > def mark_sold > > self.update_attribute(:market_status, ''sold'') > > end > > > Is it possible for this to be called via an on page link? > > > Then I''d like to ajax it so a user could just scroll down a list > > clicking all links to "mark as sold" as he comes across old inventory. > > Browser requests always are to controller methods. Any other way you are > fighting Rails'' MVC opinioned structure. > > Add a method to a controller and the route to config/routes.rb: > > def mark_sold > model = Model.find(params[:id]) > model.mark_sold > render :partial => ..., :object => model > end > > The render should generate the HTML for the changed model instance that the > AJAX will replace. > > HTH, > Jeffrey-- 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.