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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -