What is the best way to change a value on database when I change value on checkbox by ajax? I want to put a checkbox in my list of data: ex: <% @posts.each do |post| %> <tr"> <td><%= post.id %></td> <td><%= post.title %></td> <td> <%= button_group do %> <%= pill_button_link_to ''Edit'', edit_post_path(post) %> <%= pill_negative_trash_button_link_to ''Delete'', post, :confirm => ''Are you sure?'', :method => :delete %> <% end %> </td> Then I want to change an boolean value from list of posts, when I change the value of checkbox, without reloading the page. I''m looking by the best way for do this. Thanks by help! -- *Fernando Aureliano* -- 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.
What have you tried? -- 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.
I read about the Observer class, look for javascript observers and tried to find some tutorials or answer about how do it on rails. I find answers, but all about PHP. On Mon, Aug 29, 2011 at 9:49 PM, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> What have you tried? > > -- > 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. > >-- *Fernando Aureliano* -- 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.
What version of rails are you using? Are you using the default javascript with that version? -- 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.
I''m using 3.0.9 with jquery-rails On Mon, Aug 29, 2011 at 10:44 PM, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> What version of rails are you using? Are you using the default > javascript with that version? > > -- > 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. > >-- *Fernando Aureliano* -- 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.
What does this mean: "when I change value on checkbox"? Checkboxes can either be checked or unchecked. In addition, I don''t see any checkboxes in your view. -- 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.
when I change value on checkbox => when I checked or unchecked You still do not see because I''m looking for the best way to put it there. On Tue, Aug 30, 2011 at 9:38 AM, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> What does this mean: "when I change value on checkbox"? Checkboxes can > either be checked or unchecked. In addition, I don''t see any checkboxes > in your view. > > -- > 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. > >-- *Fernando Aureliano* -------------------------------------------------------------- [iOSDeveloper] - *ObjectiveC* [WebDesigner] - *CSS3&HTML5* *[WebDeveloper] - RubyOnRails* *-------------------------------------------------------------- * [portfolio] <http://www.fernandoaureliano.com> - [blog]<http://www.fernandoaureliano.com/> - [personal blog] <http://www.obsessivocompulsivo.com/> - [twitter]<http://twitter.com/Pailoro> -- 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.
It sounds like you want to place a checkbox on each object in an index view, then observe the click event in JavaScript within that index view and have the current state of that checkbox sent to an Ajax endpoint in your controller for that model. Does that sound like a good wrap-up? #foos_controller def set_status @foo = Foo.find(params[:id]) @foo.update_attribute(:status, params[:status]); render :nothing => true end #views/foos/index <%- for foo in @foos %> <p><%= foo.name %> <%= check_box_tag "foos[#{foo.id}][status]", 1, foo.status, :class => ''status'' %></p> <%- end %> #Prototype JavaScript $$(''input.status'').invoke(''observe'',''click'',function(evt){ new Ajax.Request(''/foos/set_status'',{parameters: {id: this.id.split(''_'')[1],status:$F(this)}}); }); Off the top of my head, that ought to work. Of course you''ll need to set up a route for set_status that can take a POST. Walter On Aug 30, 2011, at 10:52 AM, Fernando Aureliano wrote:> when I change value on checkbox => when I checked or unchecked > > You still do not see because I''m looking for the best way to put it > there. > > On Tue, Aug 30, 2011 at 9:38 AM, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: > What does this mean: "when I change value on checkbox"? Checkboxes > can > either be checked or unchecked. In addition, I don''t see any > checkboxes > in your view. > > -- > 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 > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . > > > > > -- > Fernando Aureliano > -------------------------------------------------------------- > [iOSDeveloper] - ObjectiveC > [WebDesigner] - CSS3&HTML5 > [WebDeveloper] - RubyOnRails > -------------------------------------------------------------- > [portfolio] - [blog] - [personal blog] - [twitter] > > > -- > 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 > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > .-- 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.
is exactly! Thanks man! It Is a good way. I will adapt the javascript to jquery! On Tue, Aug 30, 2011 at 2:51 PM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org>wrote:> It sounds like you want to place a checkbox on each object in an index > view, then observe the click event in JavaScript within that index view and > have the current state of that checkbox sent to an Ajax endpoint in your > controller for that model. Does that sound like a good wrap-up? > > #foos_controller > def set_status > @foo = Foo.find(params[:id]) > @foo.update_attribute(:status, params[:status]); > render :nothing => true > end > > #views/foos/index > <%- for foo in @foos %> > <p><%= foo.name %> <%= check_box_tag "foos[#{foo.id}][status]", 1, > foo.status, :class => ''status'' %></p> > <%- end %> > > #Prototype JavaScript > $$(''input.status'').invoke(''**observe'',''click'',function(evt)**{ > new Ajax.Request(''/foos/set_**status'',{parameters: {id: > this.id.split(''_'')[1],status:$**F(this)}}); > }); > > Off the top of my head, that ought to work. Of course you''ll need to set up > a route for set_status that can take a POST. > > Walter > > > On Aug 30, 2011, at 10:52 AM, Fernando Aureliano wrote: > > when I change value on checkbox => when I checked or unchecked >> >> You still do not see because I''m looking for the best way to put it there. >> >> On Tue, Aug 30, 2011 at 9:38 AM, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> What does this mean: "when I change value on checkbox"? Checkboxes can >> either be checked or unchecked. In addition, I don''t see any checkboxes >> in your view. >> >> -- >> 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@googlegroups.**com<rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe@**googlegroups.com<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> For more options, visit this group at http://groups.google.com/** >> group/rubyonrails-talk?hl=en<http://groups.google.com/group/rubyonrails-talk?hl=en> >> . >> >> >> >> >> -- >> Fernando Aureliano >> ------------------------------**------------------------------**-- >> [iOSDeveloper] - ObjectiveC >> [WebDesigner] - CSS3&HTML5 >> [WebDeveloper] - RubyOnRails >> ------------------------------**------------------------------**-- >> [portfolio] - [blog] - [personal blog] - [twitter] >> >> >> -- >> 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@googlegroups.**com<rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe@**googlegroups.com<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> For more options, visit this group at http://groups.google.com/** >> group/rubyonrails-talk?hl=en<http://groups.google.com/group/rubyonrails-talk?hl=en> >> . >> > > -- > 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@googlegroups.**com<rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe@**googlegroups.com<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at http://groups.google.com/** > group/rubyonrails-talk?hl=en<http://groups.google.com/group/rubyonrails-talk?hl=en> > . > >-- *Fernando Aureliano* -------------------------------------------------------------- [iOSDeveloper] - *ObjectiveC* [WebDesigner] - *CSS3&HTML5* *[WebDeveloper] - RubyOnRails* *-------------------------------------------------------------- * [portfolio] <http://www.fernandoaureliano.com> - [blog]<http://www.fernandoaureliano.com/> - [personal blog] <http://www.obsessivocompulsivo.com/> - [twitter]<http://twitter.com/Pailoro> -- 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.