ruby - Update a boolean field in db using link_to -
i have boolean field in database, how can update in rails using link_to. want have 2 link_to commands. 1 true false.
how do it? can use ajax, wanna learn pass data first.
thanks
link_to
can link target controller action. need define route route call method toggles boolean value.
for example, in controller:
class thingscontroller def toggle_foo @thing = thing.find(params[:id]) @thing.foo = !@thing.foo @thing.save end end
then route this:
resources :things, :member => { :toggle_too => :put }
then can link it:
link_to('toggle', toggle_foo_thing_path(@thing), :method => :put)
it's important not use get
method on these calls because browsers pre-load simple links on page, have effect of automatically toggling things link on page.
Comments
Post a Comment