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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -