hello,
I’m trying to implement an experimental sql command.
I have a page, with a text field inside a form, and a button that sends
this via AJAX to a controller.
In this controller, I send this string inside a
find_by_sql(params[:expert_command])
This is ok if I only want to send SQL commands for just one table, but I
want to freely send any valid SQL.
For what I see, I can send @result =
Master.find_by_sql(params[:expert_command]) and the sql is SELECT * FROM
dades limit 5, as you can see, I’m sending an SQL that affects another
table, the one that’s no called via the .find_by_sql.
Well, in the debug I have:
…
- !ruby/object:Master
attributes:
reporter: REPORTER
partner: PARTNER
period: PERIOD
product: PRODUCT
id: “1”
indicator_value: INDICATOR_VALUE
flow: FLOW
indicators: INDICATORS - !ruby/object:Master
attributes:
reporter: EU27
partner: EU27_INTRA
period: “199952”
product: “89011010”
id: “2”
indicator_value: “70417621”
flow: “1”
indicators: VALUE_IN_EUR
…
so, it says is a !ruby/object:Master, when really it’s from the table
‘dades’, and the attributes are really from the ‘dades’ table.
so, it seems it’s working fine, no matter from wich table I send the
.find_by_sql.
there’s a better way to do this ?
and, as I never know wich command is going to run, an easy way to
retrieve the attribute just one, for creating the headers, and then only
the values for creating the rows, and put them in a table ?
every value of @result will have the same attributes …
I can do the loop, and that’s all …
I also tried with: <%= @result.each {|key, value| puts “#{key} is
#{value}” } %>
but I’m getting only #
as always, thanks for your suggestions …
regards,
rai