# Rails 4 Join table query not working

**URL:** <https://www.ruby-forum.com/t/rails-4-join-table-query-not-working/239645>\
**Category:** Rails\
**Created:** [March 8, 2014, 9:49pm UTC](https://www.ruby-forum.com/t/rails-4-join-table-query-not-working/239645 "2014-03-08T21:49:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [March 8, 2014, 9:49pm UTC](https://www.ruby-forum.com/t/rails-4-join-table-query-not-working/239645/1 "2014-03-08T21:49:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [March 8, 2014, 10:18pm UTC](https://www.ruby-forum.com/t/rails-4-join-table-query-not-working/239645/2 "2014-03-08T22:18:37Z")

</div>

On 8 March 2014 20:49, Dave C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [March 8, 2014, 11:08pm UTC](https://www.ruby-forum.com/t/rails-4-join-table-query-not-working/239645/3 "2014-03-08T23:08:30Z")

</div>

On 8 March 2014 20:49, Dave C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [March 8, 2014, 11:12pm UTC](https://www.ruby-forum.com/t/rails-4-join-table-query-not-working/239645/4 "2014-03-08T23:12:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [March 8, 2014, 11:52pm UTC](https://www.ruby-forum.com/t/rails-4-join-table-query-not-working/239645/5 "2014-03-08T23:52:41Z")

</div>

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

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

Dave

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [March 8, 2014, 10:55pm UTC](https://www.ruby-forum.com/t/rails-4-join-table-query-not-working/239645/6 "2014-03-08T22:55:05Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [March 9, 2014, 10:22pm UTC](https://www.ruby-forum.com/t/rails-4-join-table-query-not-working/239645/7 "2014-03-09T22:22:05Z")

</div>

On Saturday, March 8, 2014 5:52:41 PM UTC-5, [Ruby-Forum.com](http://Ruby-Forum.com) User wrote:

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