> Oh, so you are trying to get the image url from the user's index action?
> If yes, that's not correct.
>
yes, i am trying to get image url from db

>
> You should instead have a different method name and should request for
> image url of only one specific user.
>
I have def show to get specific user

  def show
    @user= User.find_by_id(params[:id])
  end

>
> It would help in cleaning up the code and solve this issue faster, if you
> can tell me what exactly you are trying to do.
>

I want take a value image from Picture table with specific user and display
it on the screen.
can u help me... thanks :X so much much..


Joanne

>
>

> On Tue, Jun 21, 2011 at 9:22 PM, joanne ta <[email protected]> wrote:
>
>>
>> Not sure why it errors out now.
>>> Do you get the same error is it a different error this time?
>>>
>>
>> this is my index
>>
>>   def index
>>     @user= Users.all
>>     @pictograph = []
>>
>>     @user.each do |p|
>>     @pic= Picture.where(:phrase_id => :route , :culture_id =>
>> p.culturet_id).first
>>     @pic.compact!
>>      end
>>   end
>>
>> and my view is
>>
>> <td><%= image_tag url_for(:controller => "/users", :action => "index"),
>> :width => "25px", :height => "25px"%></td>
>>
>> my error:
>>   Processing by UsersController#index as
>>   User Load (1.0ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1
>> LIMIT 1
>>   PictureLoad (7.0ms)  SELECT "pictures".* FROM "pictures" WHERE
>> "pictures"."phrase_id" = 'route' AND "pictures"."culturet_id" = 1 LIMIT 1
>> Completed   in 237ms
>>
>>
>> NoMethodError (You have a nil object when you didn't expect it!
>> You might have expected an instance of Array.
>> The error occurred while evaluating nil.compact!):
>>   app/controllers/users_controller.rb:27:in `block in index'
>>   app/controllers/users_controller.rb:25:in `each'
>>   app/controllers/users_controller.rb:25:in `index'
>>
>>
>>>
>>> On Tue, Jun 21, 2011 at 9:05 PM, joanne ta <[email protected]> wrote:
>>>
>>>>
>>>> 1. Remove the send_data line, it isn't required.
>>>>
>>>> Yes, it did remove it.
>>>>
>>>>> 2. Can you check if there are any records in your pictures table? Right
>>>>> now it looks like it is returning nil.
>>>>>
>>>> Yes, It has 1 record in Picture table and 3 records in User Table
>>>>
>>>>
>>>>>
>>>>> On Tue, Jun 21, 2011 at 8:35 PM, joanne ta <[email protected]>wrote:
>>>>>
>>>>>>
>>>>>>
>>>>>> Can you paste what you have in your index method?
>>>>>>> You should not be getting this error because we have already defined
>>>>>>> @pic as an empty array.
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>>  def index
>>>>>>>
>>>>>>>     @users= User.all
>>>>>>>     @pic= []
>>>>>>>
>>>>>>>     @users.each do |p|
>>>>>>>     @pic<< Picture.where(:phrase_id => :route , :culture_id =>
>>>>>>> p.culture_id).first
>>>>>>>
>>>>>>>     end
>>>>>>>
>>>>>>>     @pic.compact!
>>>>>>>     send_data @pic.image, :type => 'image/png', :disposition =>
>>>>>>> 'inline'
>>>>>>>
>>>>>>>   end
>>>>>>>
>>>>>>>
>>>>>>> On Tue, Jun 21, 2011 at 8:10 PM, joanne ta <[email protected]>wrote:
>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Tue, Jun 21, 2011 at 10:27 AM, Chirag Singhal <
>>>>>>>> [email protected]> wrote:
>>>>>>>>
>>>>>>>>> Oh yes... sorry about that.
>>>>>>>>> I assumed that you will find picture for every query.
>>>>>>>>>
>>>>>>>>> You can try this instead:
>>>>>>>>>  def index
>>>>>>>>>   @users= User.all
>>>>>>>>>   @pic = []
>>>>>>>>>
>>>>>>>>>   @users.each do |p|
>>>>>>>>>     @pic << Picture.where(:phrase_id => :route , :culture_id =>
>>>>>>>>> p.culture_id).limit(1)
>>>>>>>>>   end
>>>>>>>>>   @pic.compact!
>>>>>>>>> end
>>>>>>>>>
>>>>>>>>> by calling compact! on the array, we will eliminate all nil object.
>>>>>>>>>
>>>>>>>>> On another note, are you sure, this is what you want to do? If you
>>>>>>>>> have 100 users, it will fire 100 sql queries which is not good.
>>>>>>>>>
>>>>>>>>> Yes i think i have that problem as well because if i remove  
>>>>>>>>> "@users.each
>>>>>>>> do |p|    "
>>>>>>>> and then it will cause undefined method of culture_id..
>>>>>>>> plus when i call @pic.compact! , it gives me
>>>>>>>>
>>>>>>>> NoMethodError (You have a nil object when you didn't expect it!
>>>>>>>> You might have expected an instance of Array.
>>>>>>>> The error occurred while evaluating nil.compact!):
>>>>>>>>   app/controllers/patients_controller.rb:29:in `index'
>>>>>>>>
>>>>>>>> what is mean? cuz i want to display picture on the browser too...
>>>>>>>>
>>>>>>>> please help... thank you very much
>>>>>>>>
>>>>>>>> Joanne
>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Tue, Jun 21, 2011 at 7:42 PM, joanne ta 
>>>>>>>>> <[email protected]>wrote:
>>>>>>>>>
>>>>>>>>>> it does not work, it is complaining other error
>>>>>>>>>>
>>>>>>>>>> NoMethodError (undefined method `image' for [nil]:Array):
>>>>>>>>>>   app/controllers/patients_controller.rb:27:in `block in index'
>>>>>>>>>>   app/controllers/patients_controller.rb:25:in `each'
>>>>>>>>>>   app/controllers/patients_controller.rb:25:in `index'
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Tue, Jun 21, 2011 at 9:57 AM, Chirag Singhal <
>>>>>>>>>> [email protected]> wrote:
>>>>>>>>>>
>>>>>>>>>>> Your index action should be something like this:
>>>>>>>>>>>
>>>>>>>>>>> def index
>>>>>>>>>>>   @users= User.all
>>>>>>>>>>>   @pic = []
>>>>>>>>>>>
>>>>>>>>>>>   @users.each do |p|
>>>>>>>>>>>     @pic << Picture.where(:phrase_id => :route , :culture_id =>
>>>>>>>>>>> p.culture_id).limit(1)
>>>>>>>>>>>   end
>>>>>>>>>>> end
>>>>>>>>>>> --
>>>>>>>>>>> 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/-/B259TKI0970J.
>>>>>>>>>>>
>>>>>>>>>>> To post to this group, send email to
>>>>>>>>>>> [email protected].
>>>>>>>>>>> To unsubscribe from this group, send email to
>>>>>>>>>>> [email protected].
>>>>>>>>>>> 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
>>>>>>>>>> [email protected].
>>>>>>>>>> To unsubscribe from this group, send email to
>>>>>>>>>> [email protected].
>>>>>>>>>> For more options, visit this group at
>>>>>>>>>> http://groups.google.com/group/rubyonrails-talk?hl=en.
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> Chirag
>>>>>>>>> http://sumeruonrails.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
>>>>>>>>> [email protected].
>>>>>>>>> To unsubscribe from this group, send email to
>>>>>>>>> [email protected].
>>>>>>>>> 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
>>>>>>>> [email protected].
>>>>>>>> To unsubscribe from this group, send email to
>>>>>>>> [email protected].
>>>>>>>> For more options, visit this group at
>>>>>>>> http://groups.google.com/group/rubyonrails-talk?hl=en.
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Chirag
>>>>>>> http://sumeruonrails.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
>>>>>>> [email protected].
>>>>>>> To unsubscribe from this group, send email to
>>>>>>> [email protected].
>>>>>>> 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
>>>>>> [email protected].
>>>>>> To unsubscribe from this group, send email to
>>>>>> [email protected].
>>>>>> For more options, visit this group at
>>>>>> http://groups.google.com/group/rubyonrails-talk?hl=en.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Chirag
>>>>> http://sumeruonrails.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 [email protected]
>>>>> .
>>>>> To unsubscribe from this group, send email to
>>>>> [email protected].
>>>>> 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 [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected].
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/rubyonrails-talk?hl=en.
>>>>
>>>
>>>
>>>
>>> --
>>> Chirag
>>> http://sumeruonrails.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 [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> 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 [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/rubyonrails-talk?hl=en.
>>
>
>
>
> --
> Chirag
> http://sumeruonrails.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 [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to