mrdakadoc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-May-16 05:17 UTC
Sql queries in rails
I have an assignment and I need to be able to run a query inputted by the user (no matter what the query). Also I need to display the result cleanly with the field names if the query was a select query. So far I have @result = ActiveRecord::Base.connection.execute(params[:query]) and in my view I have <% for result in @result %> <%= result %> <% end %> but this returns all the the data as a single line. Please help! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On May 16, 6:17 am, "mrdaka...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <mrdaka...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have an assignment and I need to be able to run a query inputted by > the user (no matter what the query). Also I need to display the result > cleanly with the field names if the query was a select query. So far I > have > > @result = ActiveRecord::Base.connection.execute(params[:query]) >Use connection.select_all and hope that the user doesn''t try and delete your database. Fred --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---