Rails 4 Join table query not working

32 views
Skip to first unread message

Dave Castellano

unread,
Mar 8, 2014, 3:49:20 PM3/8/14
to rubyonra...@googlegroups.com
Hi,
I wonder if anyone has any suggestions for solving the following issue.
I just upgraded from rails 3.2.x to 4.0.3

The following was working in 3.2.x

def show
@question = Question.find(params[:id])
session[:question_id] = @question.id
@pictures = @question.pictures

Now however, I get the error:
uninitialized constant Question::Picture (for the line @pictures =
@question.pictures)

I have a join table "pictures_questions" and as I said this was working
prior to the upgrade.

Any ideas?

Thanks,

Dave

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
Mar 8, 2014, 4:16:28 PM3/8/14
to rubyonra...@googlegroups.com
On 8 March 2014 20:49, Dave Castellano <li...@ruby-forum.com> wrote:
> Hi,
> I wonder if anyone has any suggestions for solving the following issue.
> I just upgraded from rails 3.2.x to 4.0.3
>
> The following was working in 3.2.x
>
> def show
> @question = Question.find(params[:id])
> session[:question_id] = @question.id
> @pictures = @question.pictures
>
> Now however, I get the error:
> uninitialized constant Question::Picture (for the line @pictures =
> @question.pictures)
>
> I have a join table "pictures_questions" and as I said this was working
> prior to the upgrade.

You have not shown us the important code, the code in the models
defining the relationships between them (has_many etc). Copy and
paste the first few lines of each model showing the relationship
definitions.

Do you get the problem every time you try to get pictures for a question?

Colin

Dave Castellano

unread,
Mar 8, 2014, 4:55:05 PM3/8/14
to rubyonra...@googlegroups.com
> You have not shown us the important code, the code in the models
> defining the relationships between them (has_many etc). Copy and
> paste the first few lines of each model showing the relationship
> definitions.
>
> Do you get the problem every time you try to get pictures for a
> question?
>
> Colin

class Picture < ActiveRecord::Base
attr_accessible :minisection_id, :contributor, :title,
:remote_image_url, :image

has_and_belongs_to_many :questions
has_and_belongs_to_many :minisections

class Question < ActiveRecord::Base
has_and_belongs_to_many :pictures


Yes, I cannot get past this error

Colin Law

unread,
Mar 8, 2014, 5:06:24 PM3/8/14
to rubyonra...@googlegroups.com
On 8 March 2014 20:49, Dave Castellano <li...@ruby-forum.com> wrote:
> Hi,
> I wonder if anyone has any suggestions for solving the following issue.
> I just upgraded from rails 3.2.x to 4.0.3
>
> The following was working in 3.2.x
>
> def show
> @question = Question.find(params[:id])
> session[:question_id] = @question.id
> @pictures = @question.pictures
>
> Now however, I get the error:
> uninitialized constant Question::Picture (for the line @pictures =
> @question.pictures)

Is that definitely the error? Question::Picture singular? Very odd.

Colin

>
> I have a join table "pictures_questions" and as I said this was working
> prior to the upgrade.
>
> Any ideas?
>
> Thanks,
>
> Dave
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/369738b846231b48fa7afe15f5d85c48%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

Dave Castellano

unread,
Mar 8, 2014, 5:12:27 PM3/8/14
to rubyonra...@googlegroups.com
Yes - below pasted directly from the console...

NameError (uninitialized constant Question::Picture):
app/controllers/questions_controller.rb:145:in `show'

Not sure where to even begin looking for the source of this error.

DAve

Dave Castellano

unread,
Mar 8, 2014, 5:52:41 PM3/8/14
to rubyonra...@googlegroups.com
Commented out
#include Sprockets::Helpers::RailsHelper
#include Sprockets::Helpers::IsolatedHelper

in image uploader and solved current problem... for now anyway.

Dave

mike

unread,
Mar 9, 2014, 5:20:43 PM3/9/14
to rubyonra...@googlegroups.com
Your problem is interesting, I'm not sure what's going on.  I seem to remember Sprockets::Helpers::RailsHelper and Sprockets::Helpers::IsolatedHelper were dropped in Rails 4 and people were including them in their code to make the Rails 4 pipeline backwards compatible to the Rails 3.1 pipeline.  One of the things that changed between the two was the treatment of images when you ran assets pre-compile.  Still not sure why that's affecting you, but if it's running with those two lines commented out, you're probably OK. 
Reply all
Reply to author
Forward
0 new messages