Run sql query?

hi i’ve got one action which i want it to perform a sql update query.

how can i just run a sql query within my rails app?

e.g.

def
@sql = “update … from mytable”
execute @sql
redirect_to :action => ‘list’
end

any ideas?

don’t worry, worked it out…

http://softiesonrails.com/2007/7/23/performing-a-sql-update-in-rails

Image.update_all ‘inform_police = true’, ‘user = joker’

:wink:

John.

On Dec 13, 2007, at 11:17 AM, John G. wrote:

redirect_to :action => ‘list’
end

any ideas?

I’ve done it two ways:

  1. Model.connection.execute(sql)

and

  1. ActiveRecord::Base.connection.execute(sql)

Not sure which way is considered more proper, though.

Peace,
Phillip

nice, i’ll have a look at that, thanks.

John.