Rails 4 Join table query not working

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

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

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

Dave

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

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

Commented out #include Sprockets::Helpers::RailsHelper   #include Sprockets::Helpers::IsolatedHelper

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

Dave

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.