On Thursday, June 9, 2011 8:16:28 PM UTC-6, joanne wrote:
I’m assuming this isn’t a copy/paste since it should look more like:
class User < ActiveRecord::Base
@pic = Picture.where(:album_id => ‘Album.album_id’ ,
user.where(:culture_id => ‘Culture.culture_id’)).first
Hmm, I’ll talk about this where later where you re-pasted it below
(regarding a syntax error)…
// Picture model//
Culture has_one what? It’s looking to me like you’re omitting stuff?
// album model//
has_many pictures through => 2011year
has_many pictures through => 2010year
has_many pictures through => 2009year
I’m pretty sure this is trouble. Firstly, having multiple #has_many
all with the same relationship name (:pictures) would either fail or
subsequent calls would overwrite the prior calls’ relationship metadata,
other weirdness would ensue (no sure exactly which as I’ve never tried).
What would it mean if I had an Album instance and I said:
Would I get the ones from the first #has_many, or the second, third, or
Also, the :through option on #has_many implies you’ve got a relationship
the “through” model already. So, if you said: “has_many :pictures,
=> :2009year” that would require you to already have a “has_many
above it (or something like that, not really sure what you’re trying to
Yes, but do they “#belong_to :album” too? (Also required for the
:through calls in the section above).
Umm, you’re going to show “all” your users? You usually only see this
the “index” action…
The code you had above defined #get_pic as a regular instance method on
User model, not as a class method. I’d think you’d need something like:
@user = User.find(params[:id])
@my = @user.get_pic
…but again, I can’t be sure (not enough info).
Yes, this is bad syntax. The #where class method call starts with you
passing an implicit ruby hash. Then, for the second hash entry, you say
“user.where(…)” which syntax doesn’t comprise a hash “key => value”
This is your basic syntax error. However, you’ve got many more problems
besides that. Your relationships “:album_id => ‘Album.album_id’” are
(very likely wrong). Are you trying to do a join in there? There is a
separate method for that.
it causes a syntax error
Please help . please help … thanks thanks
Next time, you’ll get better info if you post actual code as you’ve got
in your files. You can omit irrelevant methods (if they’re not
all by any of the code you do need help with). There are many other
that look problematic but I’ll just go with what I’ve commented on here.
You mentioned that you’re new to rails. Often, a lot of rails newbies
also ruby newbies. I don’t know for a fact if this is true for you or
but in general, the better your basic ruby knowledge, the better
you’ll be for doing rails work.
So, I’d recommend brushing up on your ruby. Also, as others have
to people asking questions on this list, I’d recommend working through
Either way, good luck solving your problems and learning rails.