Yennie
June 21, 2011, 5:26pm
21
On Tue, Jun 21, 2011 at 8:05 AM, joanne ta [email protected] wrote:
def index
@users= User.all
@pic= []
You would probably have fewer problems if you observed the Rails
naming conventions; e.g.
@pictures = [] # plural
@users.each do |user|
@pictures << Picture.where(:phrase_id => :route , :culture_id
=>user.culture_id).first
end
@pictures.compact !
Now it’s obvious that the next line makes no sense:
send_data @pictures.image, :type => 'image/png', :disposition
=> ‘inline’
An array of pictures doesn’t have an “image” attribute.
HTH,
Hassan S. ------------------------ [email protected]
twitter: @hassan
Yennie
June 21, 2011, 5:37pm
22
Remove the send_data line, it isn’t required.
Yes, it did remove it.
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
end
100 users, it will fire 100 sql queries which is not good.
it does not work, it is complaining other error
end
For more options, visit this group at
Yen
http://groups.google.com/group/rubyonrails-talk?hl=en .
Groups “Ruby on Rails: Talk” group.
–
For more options, visit this group at
Yen
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 .
–
Yennie
June 21, 2011, 5:48pm
23
Not sure why it errors out now.
Do you get the same error is it a different error this time?
On Tue, Jun 21, 2011 at 9:05 PM, joanne ta [email protected] wrote:
end
have 100 users, it will fire 100 sql queries which is not good.
it does not work, it is complaining other error
end
For more options, visit this group at
Yen
http://groups.google.com/group/rubyonrails-talk?hl=en .
Groups “Ruby on Rails: Talk” group.
–
[email protected] .
To post to 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
Yennie
June 21, 2011, 5:38pm
24
On 21 June 2011 16:31, joanne ta [email protected] wrote:
…
what can i do … I am really stuck now…
I think it might be a good idea for you to work through some Rails
tutorials to understand the basics of Rails. The free-to-use-online
tutorial railstutorial.org is good. It might seem that the tutorial
does not lead to the application that you want to develop but if you
work right through it you will learn a vast amount and will then be
embarrassed to look back here at the questions you were asking
Also take a good look at the Rails Guides. I mean a good look do
not just skim through them. Again you will learn a lot and the time
spent will be saved many times over.
Colin
Yennie
June 21, 2011, 5:53pm
25
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
<%= image_tag url_for(:controller => "/users", :action => "index"),
:width => "25px", :height => "25px"%>
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’
@pic as an empty array.
@pic<< Picture.where(:phrase_id => :route , :culture_id =>
You can try this instead:
NoMethodError (You have a nil object when you didn’t expect it!
@users.each do |p|
To post to this group, send email to
[email protected] .
http://sumeruonrails.com
For more options, visit this group at
You received this message because you are subscribed to the Google
To post to this group, send email to [email protected] .
http://sumeruonrails.com
You received this message because you are subscribed to the Google G.
–
http://groups.google.com/group/rubyonrails-talk?hl=en .
–
Yennie
June 21, 2011, 6:01pm
26
Oh, so you are trying to get the image url from the user’s index action?
If yes, that’s not correct.
You should instead have a different method name and should request for
image
url of only one specific user.
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.
On Tue, Jun 21, 2011 at 9:22 PM, joanne ta [email protected] wrote:
:width => “25px”, :height => “25px”%>
NoMethodError (You have a nil object when you didn’t expect it!
have 100 users, it will fire 100 sql queries which is not good.
it does not work, it is complaining other error
end
For more options, visit this group at
Yen
http://groups.google.com/group/rubyonrails-talk?hl=en .
Groups “Ruby on Rails: Talk” group.
–
To unsubscribe from this group, send email to
Thank you,
For more options, visit this group at
You received this message because you are subscribed to the Google
–
To unsubscribe from this group, send email to
“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
Yennie
June 21, 2011, 6:16pm
27
Ok, that’s clear now.
Do you use pastie (http://pastie.org/ ) or gist
(https://gist.github.com/ )?
If yes, can you paste following on any of them and reply with link?
#models
User
Picture
#controllers
UsersController
#views
users/index
On Tue, Jun 21, 2011 at 9:37 PM, joanne ta [email protected] wrote:
I have def show to get specific user
I want take a value image from Picture table with specific user and display
:width => “25px”, :height => “25px”%>
NoMethodError (You have a nil object when you didn’t expect it!
On another note, are you sure, this is what you want to do? If you
app/controllers/patients_controller.rb:29:in `index’
[email protected] > wrote:
end
To unsubscribe from this group, send email to
Thank you,
[email protected] .
–
To post to this group, send email to
To unsubscribe from this group, send email to
You received this message because you are subscribed to the Google
For more options, visit this group at
Yen
To unsubscribe from this group, send email to
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
Yennie
June 21, 2011, 6:09pm
28
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
Yennie
June 21, 2011, 6:32pm
29
Ok, that’s clear now.
Do you use pastie (http://pastie.org/ ) or gist (https://gist.github.com/ )?
If yes, can you paste following on any of them and reply with link?
No, I am using that…
#models
User
id
name
address
culture_id
Picture
id
image(binary)
phrase_id
culture_id
Culture
id
phrase_id
#controllers
UsersController
def index
@user= User.all
@pic= []
@user.each do |p|
@pic<< Picture.where(:phrase_id => :route , :culture_id =>
p.culture_id).first
@pic.compact !
end
end
def show
@user= User.find_by_id(params[:id])
end
end
#views
users/index
<%= image_tag url_for(:controller => "/patients", :action =>
"index"),
:width => "25px", :height => "25px"%>
You should instead have a different method name and should request for
can tell me what exactly you are trying to do.
def index
and my view is
Completed in 237ms
Yes, It has 1 record in Picture table and 3 records in User Table
p.culture_id).first
On Tue, Jun 21, 2011 at 8:10 PM, joanne ta [email protected] wrote:
def index
by calling compact! on the array, we will eliminate all nil
NoMethodError (You have a nil object when you didn’t expect it!
.
Google G. “Ruby on Rails: Talk” group.
–
For more options, visit this group at
To unsubscribe from this group, send email to
You received this message because you are subscribed to the Google
[email protected] .
http://groups.google.com/group/rubyonrails-talk?hl=en .
Groups “Ruby on Rails: Talk” group.
–
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 .
–
Yennie
June 21, 2011, 6:37pm
31
Ok, that’s clear now.
Do you use pastie (http://pastie.org/ ) or gist (https://gist.github.com/ )?
If yes, can you paste following on any of them and reply with link?
No, I am not using that…
#models
User
id
name
address
culture_id
Picture
id
image(binary)
phrase_id
culture_id
Culture
id
phrase_id
#controllers
UsersController
def index
@user= User.all
@pic= []
@user.each do |p|
@pic<< Picture.where(:phrase_id => :route , :culture_id =>
p.culture_id).first
@pic.compact !
end
end
def show
@user= User.find_by_id(params[:id])
end
end
#views
users/index
<%= image_tag url_for(:controller => "/users", :action => "index"),
:width => "25px", :height => "25px"%>
Yennie
June 21, 2011, 7:12pm
32
On Tue, Jun 21, 2011 at 12:52 PM, Chirag S.
[email protected] wrote:
Ok, some more questions:
So, you want to display an image of the culture associated with the
user, right?
yes
How are you uploading pictures to your database?
right now, i just using the sqlite manager to upload the blob.
http://groups.google.com/group/rubyonrails-talk?hl=en .
–
Yennie
June 21, 2011, 7:33pm
33
thanks you so much…
Joanne
Yennie
June 21, 2011, 7:30pm
34
Getting pretty late here, heading to bed. We can work on a cleaner
solution
tomorrow or others on the forum can help.
For now, this quick and dirty solution should work:
In your view
<% @users.each do |user| %>
<%= user.name %>
<%= image_tag url_for(:controller => "users", :action =>
"culture_image,
:culture_id => user.culture_id, :phrase_id => ""), :width => "25px",
:height
=> "25px"%>
<% end %>
Note that I haven’t put in a value for :phrase_id in the url, please
substitute appropriate value there as required.
In your controller
def index
@user= User.all
end
def culture_image
picture = Picture.where(:phrase_id => params[:phrase_id], :culture_id
=>
params[:culture_id]).limit(1)
if picture
send_data picture.image, :type => ‘image/png’, :disposition =>
‘inline’
else
render :status => 404
end
end
Note that you may have to modify your routes to include the new method
“culture_image”… something like this"
resources :users do
get :culture_image, :on => :collection
end
Yennie
June 22, 2011, 6:02am
35
Is it working now?
If not post the error and we’ll see how to get it to a good shape.