On 10 September 2012 03:58, Soichi Ishida li...@ruby-forum.com wrote:
item = @result.first
item.user_id
It worked fine! Thank you very much.
Now I need to study 'type Relation' :)
The reason it did not work originally is that @result is not a single
record, it is all the records that match
The problem may be at exists?
What's the status of the @result object? Is it nil? Does it have any
value? What do you get if you inspect it or print it? What's the exact
error you get?
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the
Looking at ruby docs, this is the explanation for the method - Evaluates
to true if this resource is not new? and is found on the remote service.
Using this method, you can check for resources that may have been
deleted between the object’s instantiation and actions on it.
What's the status of the @result object? Is it nil? Does it have any
value?
Since it passed the if part, 'if @result.exists?', @result does exist. I
have confirmed that.
What's the exact
error you get?
The error is simply
undefined method `user_id' for
--
Posted via
Item has a belongs_to :user, right?
In any case, what do you get when you print or inspect @result?
--
Posted via http://www.ruby-forum.com/.
--
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
Pradeep Singh wrote in post #1075257:
Item has a belongs_to :user, right?
yes
In any case, what do you get when you print or inspect @result?
if I print it,
#ActiveRecord::Relation:0x0100f24800
is what I get.
--
Posted via http://www.ruby-forum.com/.
--
You received this message
On Sun, Sep 9, 2012 at 9:45 PM, Soichi Ishida li...@ruby-forum.com wrote:
Pradeep Singh wrote in post #1075257:
Item has a belongs_to :user, right?
yes
In any case, what do you get when you print or inspect @result?
if I print it,
#ActiveRecord::Relation:0x0100f24800
is what I
sorry, 'Item' is actually named 'Take' here.
--
Posted via http://www.ruby-forum.com/.
--
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@googlegroups.com.
To unsubscribe from this
I see, so the object you're getting is of type Relation.
Just for kicks I tried this in rails console for my own Item class. Same
thing happens to me - no method user_id.
You need to get the item object from the @result object. This works -
item = @result.first
item.user_id
There might be
item = @result.first
item.user_id
It worked fine! Thank you very much.
Now I need to study 'type Relation' :)
soichi
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups Ruby
on Rails: Talk group.
To post to this group,
10 matches
Mail list logo