Ruby on Rails Tuesday, August 30, 2011

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@ruby-forum.com>
> 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.
> 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
> .
>
>
>
>
> --
> 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.
> 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
> .

--
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.
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.

No comments:

Post a Comment