Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot update record position when scoped to enum #298

Closed
Zmokizmoghi opened this issue Jan 19, 2018 · 3 comments
Closed

Cannot update record position when scoped to enum #298

Zmokizmoghi opened this issue Jan 19, 2018 · 3 comments

Comments

@Zmokizmoghi
Copy link

class Person < ApplicationRecord
	acts_as_list scope: :position, column: :sort
	
	enum position: {
    	director: 0,
    	teacher: 1
  	}
end
Person.find(1).move_to_top

fails with

NoMethodError: undefined method `position_id' for #<Person:0x007f88bd86af40>

Ruby version: 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
Rails version: 5.1.4
Sysytem: OS X 10.13.1

@brendon
Copy link
Owner

brendon commented Jan 19, 2018

Hi @Zmokizmoghi, have a bit of a dig through the documentation. acts_as_list always appends _id to the scope if you supply a symbol. Supply an array instead [:position]. In saying this, I don't know how you'll get on with your current use case. Using the column name position for starters, and then it being an enum… I guess you can only try :)

@Zmokizmoghi
Copy link
Author

Hi @brendon, thanks for explanations, and for this great gem also ;-)

@brendon
Copy link
Owner

brendon commented Jan 19, 2018

You're welcome :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants