Ask A Question

Notifications

You’re not receiving notifications from this thread.

update a model attribute with ujs

Joel asked in Javascript

i have a page that displays games(model) with a select box for the game result outcome. Game model has_one :result, autosave: true and
I have a unique id for each row in the table based on the game id and I am using materialize rails which attaches a class of "active selected" to whichever choice is selected in the select dropdown(these correspond to the enum keys. i would like to use ujs to update the result whenever the user selects from the select dropdown. I am haven't done much with ujs in rails but it seems like it should be fairly simple. Can anyone give some guidance on how this would be setup?
result model has:

enum outcome: {
undecided: 0,
white_won: 1,
black_won: 2,
white_forfeit: 3,
black_forfeit: 4,
draw: 5,
  }
Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.