Error of looping in rails

Hi,
I am writing this code in purpose that i can i select image from the
picture table and i want to get all the user so i can loop through
user1 , user2 …

and display the pic on bowers…

def show_image

@id  = User.find(:all, :select => 'user.id')

for id in @id

    @image = ActiveRecord::Base.connection.select_value('select

image from Picture pic
inner join Cultures c on pic.culture_id = c.id
inner join user pt on pt.id = p.user
where pt.id = “id”’);

end

send_data @image, :type => ‘image/png’, :disposition => ‘inline’
end

and i get an error "(SQLite3::SQLException: ambiguous column name: id:
"

Please help and give me some advices… Big thanks for all

The problem is here: “where pt.id = “id”’”

SQL cannot tell which id column you are talking about. Be more
specific, something like:

where pt=“user.id”

However, the code is working against the conventions of Rails, which is
why you are having problems and the code is so ugly.

There seem to be a few moving parts in this machine - Users, Pictures,
and Cultures. How do these relate to each other? There is surely a
much better way to represent what you are looking for.

Amritpal, please stop posting several messages asking the same thing.
If you have more info to add, contribute to your original thread.

On 14 June 2011 02:41, Yennie [email protected] wrote:

Hi,
I am writing this code in purpose that i can i select image from the
picture table and i want to get all the user so i can loop through
user1 , user2 …

and display the pic on bowers…

Please help and give me some advices… Big thanks for all

Why aren’t you using the associations you have set up in your model to
loop pictures?

Your table names seem all over the place: capital letters and singular
names… it’s not going to help the Rails magic to work.

If you just want an array of user ids:
@ids = User.find(:all).map(&:id)

…but I really doubt that your approach is the best one (or even a
good one). You should be doing something along the lines of:

controller code

@users = User.all

view code

@users.each do |user|

you can render user name, etc here

user.albums.each do |album|
# access to album info here
album.pictures.each do |picture|
# some picture stuff here
end
end
end

but… it may be best for you to take a moment, flick back to page 1
of Agile Web D. With Rails, and work quietly through the
tutorial again.

Thank you very much

On Tue, Jun 14, 2011 at 4:08 AM, Michael P. [email protected]
wrote:

Amritpal, please stop posting several messages asking the same thing.

    This is not my post

On 14 June 2011 09:24, amritpal pathak [email protected]
wrote:

On Tue, Jun 14, 2011 at 4:08 AM, Michael P. [email protected] wrote:

Amritpal, please stop posting several messages asking the same thing.

This is not my post

Of course not… I believe you (from your new email address…). I’m
sorry.

It doesn’t help when Joanne/Yennie keeps changing their display name
with every posting… you can understand our confusion (what with the
four-or-more identities you post under, you must get very confused
yourself :-/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs