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 -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I think the problem is that you dont have :culture_id => in the Picture model. Is that right? On Tue, Jun 14, 2011 at 7:19 AM, Yennie <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I have culture_id in Picture Model as well On Tue, Jun 14, 2011 at 10:33 AM, Noel <wwydiywd-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I think the problem is that you dont have :culture_id => in the > Picture model. Is that right? > > On Tue, Jun 14, 2011 at 7:19 AM, Yennie <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > 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 > > > > -- > > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- -------------------------------- Thank you, Yen -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 -- 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. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 On Tue, Jun 14, 2011 at 11:19 AM, Tim Shaffer <timshaffer-BUHhN+a2lJ4@public.gmane.org> wrote:> 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 > > -- > 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. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 <timshaffer-BUHhN+a2lJ4@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- -------------------------------- Thank you, Yen -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 On Tue, Jun 14, 2011 at 2:15 PM, Tim Shaffer <timshaffer-BUHhN+a2lJ4@public.gmane.org> wrote:> 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. > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- -------------------------------- Thank you, Yen -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 On Tue, Jun 14, 2011 at 11:26 AM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > > > > > > On Tue, Jun 14, 2011 at 2:15 PM, Tim Shaffer <timshaffer-BUHhN+a2lJ4@public.gmane.org> wrote: >> >> 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. >> >> -- >> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > -- > -------------------------------- > > Thank you, > > Yen > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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? -- 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/-/L8NlBtBPU7AJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> I run those code in terminal user_instance = User.find(1) => it shows me allthe data in the User table and then i run Picture.where(:album_id => :album, :culture_id => user_instance.culture_id).first> =>nilAs 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. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.