0

I have a column in database with datatype boolean

class Table < ActiveRecord::Migration
  def change
    create_table :services do |t|

      t.boolean :recommend, :default => false
      t.timestamps
    end
  end
end

I want use to click a button or check yes or no to a form so when user submits a review, they would recommend and change the database to true.

How would I do such a thing?

I have a button:

<div class="field-container"><%= f.button :recommend %></div>

If user clicks on it, I'm not sure if it'll save true to database? Do I need to add more to this?

Thanks!

1
  • You're not sure? It's quite easy to test if it does or not. Commented Jun 17, 2013 at 3:13

2 Answers 2

2

Since you want to have button and not a checkbox for the boolean field, you can have a checkbox which is styled like a button.

http://jsfiddle.net/zAFND/4/

and then

<%= f.check_box :recommend %>
Sign up to request clarification or add additional context in comments.

Comments

1

Since you have a boolean value, you can very easily use a form_for check_box to accomplish what you're trying to do:

<%= f.check_box :recommend %>

This will generate markup for a form where the value of params[:recommend] in your controller action will be understood to be a boolean value when updating (or creating) the record through ActiveRecord.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.