ruby on rails - how to associate checkbox used in view to update a field in a RoR table? -
i have created new field called "reviewed" in 1 of tables called "posts". everytime checkmarks prior post, want reviewed approval prior display.
the "reviewed" field in table defaulted true. here's schema.db
create_table "posts", :force => true |t| t.text "content" t.integer "user_id" t.timestamp "created_at", :null => false t.timestamp "updated_at", :null => false t.boolean "reviewed", :default => true
here's code in view i'm using checkmark
<%= label_tag(:post_reviewed, "review post") %> <%= check_box_tag(:post_reviewed) %>
i want every time checkbox checked, reviewed field set false post not displayed until review , update true. how can this?
you have in view:
<%= form_for :post |f| %> .. <% end %>
so, try add it:
<%= f.check_box :reviewed %>
that should automatically associate desired object.
let me know if works you.
Comments
Post a Comment