I want to create an internal admin view to display the output of "show variables" from mysql. What''s the best approach do this? For example, I''m doing something like this: @variables = ActiveRecord::Base.find_by_sql "show variables;" Then, I get stuff like this back (227 elements in @variables) in script/console: >> @variables[0] => #<ActiveRecord::Base:0x3296eec @attributes={"Variable_name"=>"auto_increment_increment", "Value"=>"1"}> However, I''m not sure how to get Variable_name and Value; do I access this as a Hash element? An attribute? Should I create a custom Model class such as this? class MySql < ActiveRecord::Base Thanks in advance. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom wrote:>> >> @variables[0] >> => #<ActiveRecord::Base:0x3296eec >> @attributes={"Variable_name"=>"auto_increment_increment", "Value"=>"1"}> >> >> However, I''m not sure how to get Variable_name and Value; do I access >> this as a Hash element? An attribute? > > What happens if you do: > > @variables[0][:Variable_name] > @variables[0][:Value] > > ?Hi, Philip. Thanks. Unfortunately, I get the same error as before (since I had already tried a variation: @variables[0]["Variable_name"])>> @variables[0][:Variable_name]NoMethodError: undefined method `abstract_class?'' for Object:Class from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1367:in `class_of_active_record_descendant'' from ./script/../config/../config/../vendor/rails/activerecord/lib/activ -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ben Knight wrote:> I want to create an internal admin view to display the output of "show > variables" from mysql. What''s the best approach do this? > > For example, I''m doing something like this: > > @variables = ActiveRecord::Base.find_by_sql "show variables;" > > Then, I get stuff like this back (227 elements in @variables) in > script/console: > > >> @variables[0] > => #<ActiveRecord::Base:0x3296eec > @attributes={"Variable_name"=>"auto_increment_increment", "Value"=>"1"}> > > However, I''m not sure how to get Variable_name and Value; do I access > this as a Hash element? An attribute? > > Should I create a custom Model class such as this? > class MySql < ActiveRecord::Base > > Thanks in advance. >Try something like: ActiveRecord::Base.connection.select_all "show variables" -- Jack Christensen jackc-/SOt/BrQZzMOf2zXYvRtkodd74u8MsAO@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jack Christensen wrote:> Ben Knight wrote: >> >> @variables[0] >> > Try something like: > > ActiveRecord::Base.connection.select_all "show variables" > > -- > Jack Christensen > jackc-/SOt/BrQZzMOf2zXYvRtkodd74u8MsAO@public.gmane.orgThanks, Jack -- that did the trick! Here is some sample output:>> @variables[0]=> {"Variable_name"=>"auto_increment_increment", "Value"=>"1"}>> @variables[0]["Variable_name"]=> "auto_increment_increment">> @variables[0]["Value"]=> "1" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> I want to create an internal admin view to display the output of "show > variables" from mysql. What''s the best approach do this? > > For example, I''m doing something like this: > > @variables = ActiveRecord::Base.find_by_sql "show variables;" > > Then, I get stuff like this back (227 elements in @variables) in > script/console: > > >> @variables[0] > => #<ActiveRecord::Base:0x3296eec > @attributes={"Variable_name"=>"auto_increment_increment", "Value"=>"1"}> > > However, I''m not sure how to get Variable_name and Value; do I access > this as a Hash element? An attribute?What happens if you do: @variables[0][:Variable_name] @variables[0][:Value] ? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---