Ruby on Rails Friday, January 19, 2018

Did you use the self.table_name = 'servicename_user' assignment in your User class? That's a critical part of getting a legacy database to work with Rails.

Walter

> On Jan 19, 2018, at 1:17 AM, 정인중 <mu29@yeoubi.net> wrote:
>
> I am switching old systems created with php to Rails.
> I want to use the table 'servicename_user' of the previous system in the User model.
> There is no problem with the console or controller, but when I try to create the rspec test, I get the following error message:
>
> 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
>
> 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.
>
> --
> 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/ad957836-412a-44a8-b93f-d3e6c1e5d112%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
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/4F84CEC6-D16F-4A74-9A98-9F06BE7C7D9D%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment