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

In questions_controller:
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

On 8 March 2014 20:49, Dave C. [email protected] wrote:

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

On 8 March 2014 20:49, Dave C. [email protected] wrote:

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’

OK, looks like I’m getting ubiquitous “NameError”

NameError (uninitialized constant Sprockets::Helpers):
app/uploaders/image_uploader.rb:10:in <class:ImageUploader>' app/uploaders/image_uploader.rb:3:in<top (required)>’
app/models/picture.rb:6:in <class:Picture>' app/models/picture.rb:1:in<top (required)>’
app/controllers/pictures_controller.rb:7:in `index’
error also.

May be a config problem??

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

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

On Saturday, March 8, 2014 5:52:41 PM UTC-5, Ruby-Forum.com User wrote:

Posted via http://www.ruby-forum.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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs