Ruby on Rails
Sunday, January 21, 2018
Thank you for reply :)
2018년 1월 19일 금요일 오후 6시 1분 36초 UTC+9, Frederick Cheung 님의 말:
-- I have used byebug to find out backtrace and realized that it was STI related issue. The servicename_user table was using type column.
Problem solved by setting
self.inheritance_column = :_type_disabled
2018년 1월 19일 금요일 오후 6시 1분 36초 UTC+9, Frederick Cheung 님의 말:
On Friday, January 19, 2018 at 8:47:29 AM UTC, 정인중 wrote:
> Failure/Error: it { should validate_presence_of(:email) }
>
>
> LoadError:
> Unable to autoload constant USER, expected /Users/injung/Github/api/app/models/user.rb to define it
>
Are there any references to USER (all caps) anywhere in your app? The next one of the backtrack would be a good place to look. When playing around in the console rails only loads files that it needs to load, whereas if my memory is correct in tests it loads everything upfront. In particular if you have (for example) a controller that you don't use, maybe an experiment that didn't work out that references USER, then this wouldn't be triggered in develipment unless you accessed that controller but would be in tests.
>
> However, my user.rb file is located exactly where the error message was mentioned.
> For reference, the test was written as follows.
>
>
> require_relative '../../app/models/user'
>
>
> describe User, type: :model do
> context 'validation' do
> it { should validate_presence_of(:author) }
> it { should validate_presence_of(:email) }
> end
> end
>
>
> The user model is as follows.
>
>
>
> class User < ApplicationRecord
> self.table_name = 'servicename_user'
> end
>
> After some search, I found out that If my table name is servicename_user, my user model should be in app/models/servicename/user, but I do not want to do like this. Is there any good way?
> It is difficult to change the table name because it references a lot on older systems.
The table name shouldn't matter as far as constant lookup is concerned and looks like you're setting it correctly.
Fred
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b8c9d076-67c7-4bc5-ae4a-e25cc17eb965%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment