undefined method culture_id

26 views
Skip to first unread message

Yennie

unread,
Jun 14, 2011, 10:19:34 AM6/14/11
to Ruby on Rails: Talk

Hi all,

I have an error which said undefined method culture_id
but in the DB, it contains "culture_id" in user table..

Picture.where(:album_id => :album, :culture_id =>
User.culture_id).first

Please help to solve this problem...

THanks

Noel

unread,
Jun 14, 2011, 10:33:40 AM6/14/11
to rubyonra...@googlegroups.com
I think the problem is that you dont have :culture_id => in the
Picture model. Is that right?

> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

joanne ta

unread,
Jun 14, 2011, 10:50:33 AM6/14/11
to rubyonra...@googlegroups.com
I have culture_id in Picture Model as well
--
--------------------------------

Thank you,

Yen

Tim Shaffer

unread,
Jun 14, 2011, 11:19:04 AM6/14/11
to rubyonra...@googlegroups.com
The problem is that you're using "User.culture_id"

The class User doesn't have a method called "culture_id"

You probably want to use a user instance instead of the class:

user_instance = User.find(1)
Picture.where(:album_id => :album, :culture_id => user_instance.culture_id).first

joanne ta

unread,
Jun 14, 2011, 11:43:31 AM6/14/11
to rubyonra...@googlegroups.com
user_instance = User.find(1)
@pic = Picture.where(:album_id => :album, :culture_id => user_instance.culture_id).
first


ya, it work but it return nil.. and i cannot take value from Picture model
it causes me undefined method image when i call @pic.image




--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/OR8oidO5TWwJ.

Tim Shaffer

unread,
Jun 14, 2011, 12:01:08 PM6/14/11
to rubyonra...@googlegroups.com
I'm not sure what you're trying to say.

When you use "culture_id" in the where clause, it needs to have a value. This value can come from any number of places such as a user instance, query parameter, or even be hard coded.

joanne ta

unread,
Jun 14, 2011, 2:11:16 PM6/14/11
to rubyonra...@googlegroups.com
i did try the code from above on rails console. it is return nil...
so can you explain it please

On Tue, Jun 14, 2011 at 12:01 PM, Tim Shaffer <timsh...@me.com> wrote:
I'm not sure what you're trying to say.

When you use "culture_id" in the where clause, it needs to have a value. This value can come from any number of places such as a user instance, query parameter, or even be hard coded.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/zcHnTSvbAHIJ.

To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Tim Shaffer

unread,
Jun 14, 2011, 2:15:00 PM6/14/11
to rubyonra...@googlegroups.com
I cannot explain it. You're not providing enough information about your environment and any error messages you may or may not be receiving.

Which part returns nil?

Did you run this on the command line?
  user_instance = User.find(1)

Did it return nil? If so, you probably don't have a user by the ID of 1 in your database. Adjust accordingly to fit your environment.

joanne ta

unread,
Jun 14, 2011, 2:26:39 PM6/14/11
to rubyonra...@googlegroups.com
I run those code in terminal

user_instance = User.find(1)

=> it shows me all the data in the User table
and then i run

Picture.where(:album_id => :album, :culture_id => user_instance.culture_id).first
=>nil





--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/m-fUx744LKkJ.

To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Noel

unread,
Jun 14, 2011, 2:54:01 PM6/14/11
to rubyonra...@googlegroups.com
does
user_instance.culture_id
return something?

try doing the Picture query by putting in the culture_id yourself.
maybe you dont have a picture with that culture_id

Picture.where(:album_id => :album, :culture_id =>3).first

Tim Shaffer

unread,
Jun 14, 2011, 3:08:18 PM6/14/11
to rubyonra...@googlegroups.com
Also double check that there is a picture that has an album_id of ":album"

Kind of weird that you're using a symbol there. Are you sure you don't mean to be using a variable instead?

Andrew Skegg

unread,
Jun 15, 2011, 7:52:01 PM6/15/11
to rubyonra...@googlegroups.com
> I run those code in terminal user_instance = User.find(1) => it shows me all
the data in the User table and then i run Picture.where(:album_id
=> :album, :culture_id => user_instance.culture_id).first
> =>nil

As others have said, you are not providing enough information to diagnoise the
problem. Let's break it down.

Find the first user. Does it have a culture_id field? What is it's value?

user = User.first

Find all the pictures associated with this user. Are there any? Do any have
the same culture_id as the user?

Picture.where(:user => user)

I am guessing you have a particular album in mind, which collates various
pictures (why are you using a symbol here?). Does this album contain the
picture with the "correct" culture_id?

Album.where(:user=> user, :album => album).pictures

If the answer to all these questions is "yes", then your code should work. If
not, it will tell you excactly where you have gone wrong.

Reply all
Reply to author
Forward
0 new messages