checkbox returning true or false in rails

rico_mac

I am trying to create a form that has an option, which if chosen, via a checkbox, returns true or false to the database. I have added the column to my db like so

rails g migration AddWantSellToPosts want_sell?:boolean

and also added the necessary params to the controllers page so that data is passed through. However no value is being returned to the database. I suspected it was my implementation of the check_box in Rails, however I am still not sure.

this is the html.erb

<%= f.text_field :price, :id => 'price' %>
<%= f.check_box :want_sell? %>

this is the posts_controller.rb

  before_action :authenticate_user!, only: [:new, :create, :destroy]

....

@post = Post.new params[:post].permit(:description, :picture, :tag_names, :price, :want_sell?)
@post.user = current_user

I should add i am new to rails and coding in general so I may be missing something really obvious!

Thanks

Damien Roche

As in my comment...

Rename the column to want_sell, want_sell? is a dynamic method that Rails will make available to check if the boolean is true/false. Also be sure to call @post.save.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

wxPython checkbox true or false

From Dev

Checkbox value true/false

From Dev

wxPython checkbox true or false

From Dev

Query returning true/false

From Dev

else if returning true when false

From Dev

State set to true is returning false

From Dev

Method returning 'true' when it should be returning 'false'

From Dev

Once checkbox is true, how do you make it false once clicked again? (Rails 4)

From Dev

Checkbox is always returning false even when checked

From Dev

Checkbox is always returning true, even when not checked

From Dev

Userform CommandButton to Populate based on CheckBox True/False

From Dev

Checkbox value changes to true/false after click

From Dev

adding a column with TRUE/FALSE and showing that as a checkbox

From Dev

Store checkbox values in JSON with true or false

From Dev

Both true and false got from checkbox if it is checked

From Dev

adding a column with TRUE/FALSE and showing that as a checkbox

From Dev

.prop("checked", false) makes checkbox true

From Dev

Toggling True and False in Redux State via a Checkbox

From Dev

Ternary operators returning "true : false". Why?

From Dev

Returning true or false if a certain string is found

From Dev

if condition with ternary operator not returning true or false

From Dev

Pandas any() returning false with true values present

From Dev

PHP OOP checking if a class is returning true or false?

From Dev

Ternary operators returning "true : false". Why?

From Dev

Should be returning true but returns false instead?

From Dev

Java: if and else returning true or false at every condition

From Dev

JCheckBox Always Returning True/False But Not Changing

From Dev

password_verify not returning true/false

From Dev

NSURLSession method returning true or false on login

Related Related

  1. 1

    wxPython checkbox true or false

  2. 2

    Checkbox value true/false

  3. 3

    wxPython checkbox true or false

  4. 4

    Query returning true/false

  5. 5

    else if returning true when false

  6. 6

    State set to true is returning false

  7. 7

    Method returning 'true' when it should be returning 'false'

  8. 8

    Once checkbox is true, how do you make it false once clicked again? (Rails 4)

  9. 9

    Checkbox is always returning false even when checked

  10. 10

    Checkbox is always returning true, even when not checked

  11. 11

    Userform CommandButton to Populate based on CheckBox True/False

  12. 12

    Checkbox value changes to true/false after click

  13. 13

    adding a column with TRUE/FALSE and showing that as a checkbox

  14. 14

    Store checkbox values in JSON with true or false

  15. 15

    Both true and false got from checkbox if it is checked

  16. 16

    adding a column with TRUE/FALSE and showing that as a checkbox

  17. 17

    .prop("checked", false) makes checkbox true

  18. 18

    Toggling True and False in Redux State via a Checkbox

  19. 19

    Ternary operators returning "true : false". Why?

  20. 20

    Returning true or false if a certain string is found

  21. 21

    if condition with ternary operator not returning true or false

  22. 22

    Pandas any() returning false with true values present

  23. 23

    PHP OOP checking if a class is returning true or false?

  24. 24

    Ternary operators returning "true : false". Why?

  25. 25

    Should be returning true but returns false instead?

  26. 26

    Java: if and else returning true or false at every condition

  27. 27

    JCheckBox Always Returning True/False But Not Changing

  28. 28

    password_verify not returning true/false

  29. 29

    NSURLSession method returning true or false on login

HotTag

Archive