Rails admin field error in has_and_belongs_to_many association

100 views
Skip to first unread message

alexan...@gmail.com

unread,
Mar 3, 2017, 4:17:46 AM3/3/17
to rails_admin
Hi everyone,

When I try to edit or create a user, through rails admin, the template doesn't render and I get an error "undefined method `company' for #<User:0x00000006b4f1f8>". You can find my user model, my company model and the trace from rails console here https://gist.github.com/alexdor/98a01a1265b38242884e8b45c6e18c81 . Am I doing something wrong or is this a bug? I have the same association between user and project model and they work fine. 

Thank you in advanced,
Alexandros

Eduardo Moreno

unread,
Mar 3, 2017, 7:12:50 AM3/3/17
to rails...@googlegroups.com
Hi Alexandros,

Did you check the association in a console (rails c)? populating your database before (of course), review your inflections to prevent some problem with the inflect.irregular('company', 'companies'), try adding the foreign_key param to the model also to be 100% sure.

Regards.
 

--
You received this message because you are subscribed to the Google Groups "rails_admin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rails_admin+unsubscribe@googlegroups.com.
To post to this group, send email to rails...@googlegroups.com.
Visit this group at https://groups.google.com/group/rails_admin.
For more options, visit https://groups.google.com/d/optout.



--

Αλέξανδρος Δ

unread,
Mar 3, 2017, 8:14:42 AM3/3/17
to rails...@googlegroups.com
Hi Eduardo,

First of all thanks for your help. The association seems to be ok through the rails c and through my controllers as well. I can't find anything wrong with my inflections (I don't have any custom ones and I tried adding inflect.irregular('company', 'companies') to the initializers/inflections.rb). Foreign key didn't fix the problem as well.  

I forgot to mention that I'm using rails 4.2.8 with mongoid 5.2.0.

Στις Παρ, 3 Μαρ 2017 στις 2:12 μ.μ., ο/η Eduardo Moreno <ejm...@gmail.com> έγραψε:
Hi Alexandros,

Did you check the association in a console (rails c)? populating your database before (of course), review your inflections to prevent some problem with the inflect.irregular('company', 'companies'), try adding the foreign_key param to the model also to be 100% sure.

Regards.
 
2017-03-03 5:17 GMT-04:00 <alexan...@gmail.com>:
Hi everyone,

When I try to edit or create a user, through rails admin, the template doesn't render and I get an error "undefined method `company' for #<User:0x00000006b4f1f8>". You can find my user model, my company model and the trace from rails console here https://gist.github.com/alexdor/98a01a1265b38242884e8b45c6e18c81 . Am I doing something wrong or is this a bug? I have the same association between user and project model and they work fine. 

Thank you in advanced,
Alexandros

--
You received this message because you are subscribed to the Google Groups "rails_admin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rails_admin...@googlegroups.com.

To post to this group, send email to rails...@googlegroups.com.
Visit this group at https://groups.google.com/group/rails_admin.
For more options, visit https://groups.google.com/d/optout.



--

--
You received this message because you are subscribed to a topic in the Google Groups "rails_admin" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rails_admin/d0d7omDx3w4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rails_admin...@googlegroups.com.

Eduardo Moreno

unread,
Mar 3, 2017, 9:52:26 AM3/3/17
to rails...@googlegroups.com
Hi Alexandros,

I check your gist and everything looks ok to me, I would say that you must add attr_accessible but you're using rails 4.2.8 so it's not needed.

Just for the sake of testing, before to send an issue:
- Be sure that in rails c ->  User.first.companies and Company.first.users gives you the expected results.
- Add the join_table param to both sides of the relationship with the name of the table in the middle ('companies_users' I think).
- Force the inflection (I know that you already try this, but do it again please) adding the inflect.irregular('company', 'companies') and restart your puma / webrick server to force reinitialization, ctrl+c, rails s.
- As the last resort try downgrading rails_admin gem version to 1.0.0.

I have a similar situation with a table in Postgresql and it works fine with 1.0.0, I know that you probably already googleit a lot about a similar case with mongoid and rails_admin without luck (I'm also did that).

Let me know if that works.

Regards. 


2017-03-03 9:14 GMT-04:00 Αλέξανδρος Δ <alexan...@gmail.com>:
Hi Eduardo,

First of all thanks for your help. The association seems to be ok through the rails c and through my controllers as well. I can't find anything wrong with my inflections (I don't have any custom ones and I tried adding inflect.irregular('company', 'companies') to the initializers/inflections.rb). Foreign key didn't fix the problem as well.  

I forgot to mention that I'm using rails 4.2.8 with mongoid 5.2.0.

Στις Παρ, 3 Μαρ 2017 στις 2:12 μ.μ., ο/η Eduardo Moreno <ejm...@gmail.com> έγραψε:
Hi Alexandros,

Did you check the association in a console (rails c)? populating your database before (of course), review your inflections to prevent some problem with the inflect.irregular('company', 'companies'), try adding the foreign_key param to the model also to be 100% sure.

Regards.
 
2017-03-03 5:17 GMT-04:00 <alexan...@gmail.com>:
Hi everyone,

When I try to edit or create a user, through rails admin, the template doesn't render and I get an error "undefined method `company' for #<User:0x00000006b4f1f8>". You can find my user model, my company model and the trace from rails console here https://gist.github.com/alexdor/98a01a1265b38242884e8b45c6e18c81 . Am I doing something wrong or is this a bug? I have the same association between user and project model and they work fine. 

Thank you in advanced,
Alexandros

--
You received this message because you are subscribed to the Google Groups "rails_admin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rails_admin+unsubscribe@googlegroups.com.

To post to this group, send email to rails...@googlegroups.com.
Visit this group at https://groups.google.com/group/rails_admin.
For more options, visit https://groups.google.com/d/optout.



--

--
You received this message because you are subscribed to a topic in the Google Groups "rails_admin" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rails_admin/d0d7omDx3w4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rails_admin+unsubscribe@googlegroups.com.

To post to this group, send email to rails...@googlegroups.com.
Visit this group at https://groups.google.com/group/rails_admin.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "rails_admin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rails_admin+unsubscribe@googlegroups.com.

To post to this group, send email to rails...@googlegroups.com.
Visit this group at https://groups.google.com/group/rails_admin.
For more options, visit https://groups.google.com/d/optout.

Αλέξανδρος Δ

unread,
Mar 3, 2017, 10:24:00 AM3/3/17
to rails...@googlegroups.com
- rails c returns expected results
- join_table is not available on mongoid
- Forced the inflection and restart, didn't resolve the issue
- Downgraded rails_admin gem version to 1.0.0. and I got the same error.

Should I submit a bug report? 

Best regards,
Alexandros

To unsubscribe from this group and stop receiving emails from it, send an email to rails_admin...@googlegroups.com.

To post to this group, send email to rails...@googlegroups.com.
Visit this group at https://groups.google.com/group/rails_admin.
For more options, visit https://groups.google.com/d/optout.



--

--
You received this message because you are subscribed to a topic in the Google Groups "rails_admin" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rails_admin/d0d7omDx3w4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rails_admin...@googlegroups.com.

To post to this group, send email to rails...@googlegroups.com.
Visit this group at https://groups.google.com/group/rails_admin.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "rails_admin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rails_admin...@googlegroups.com.

To post to this group, send email to rails...@googlegroups.com.
Visit this group at https://groups.google.com/group/rails_admin.
For more options, visit https://groups.google.com/d/optout.



--

--
You received this message because you are subscribed to a topic in the Google Groups "rails_admin" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rails_admin/d0d7omDx3w4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rails_admin...@googlegroups.com.

Eduardo Moreno

unread,
Mar 3, 2017, 11:15:48 AM3/3/17
to rails...@googlegroups.com
Alexandros,

Of course, you could try submitting a bug report or wait until somebody else review your issue here.

If you decided to go with the bug report, please include rails_admin version, mongoid version, rails version and the console log and the Gist, also explain that you already tried changing inflections, checked in rails console the association, etc.

Sorry for not be helpful this time...

I would be following the issue as well, maybe you'll find someone who can help.

Regards.

To unsubscribe from this group and stop receiving emails from it, send an email to rails_admin+unsubscribe@googlegroups.com.

To post to this group, send email to rails...@googlegroups.com.
Visit this group at https://groups.google.com/group/rails_admin.
For more options, visit https://groups.google.com/d/optout.



--

--
You received this message because you are subscribed to a topic in the Google Groups "rails_admin" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rails_admin/d0d7omDx3w4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rails_admin+unsubscribe@googlegroups.com.

To post to this group, send email to rails...@googlegroups.com.
Visit this group at https://groups.google.com/group/rails_admin.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "rails_admin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rails_admin+unsubscribe@googlegroups.com.

To post to this group, send email to rails...@googlegroups.com.
Visit this group at https://groups.google.com/group/rails_admin.
For more options, visit https://groups.google.com/d/optout.



--

--
You received this message because you are subscribed to a topic in the Google Groups "rails_admin" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rails_admin/d0d7omDx3w4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rails_admin+unsubscribe@googlegroups.com.

To post to this group, send email to rails...@googlegroups.com.
Visit this group at https://groups.google.com/group/rails_admin.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "rails_admin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rails_admin+unsubscribe@googlegroups.com.

To post to this group, send email to rails...@googlegroups.com.
Visit this group at https://groups.google.com/group/rails_admin.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages