Rails 4: Can I update enums using a button? -
i looking @ updating database. since have rails 4 found use enums. if items statuses set 0
defualt, able add button change status 1
once clicked.
how do that? there example demonstrates because i'm looking have default status can changed in view button.
is possibility , how go it? state machine gem better type of issue?
you can update enums other attribute: use update
action.
to send new attribute value use hidden form or attach "form" data link or button.
this how can link/button:
link_to 'update enum', item_path(@item), data: { method: :patch, params: { item: { status: 1 } } }
you have adapt path , names in data-params
hash names using.
depening on use case might want include remote: true
send ajax request.
Comments
Post a Comment