sinatra - Access Ruby accessors using block variables -


I have an application that I am using an active record to access a database. I am trying to get information and put it in a hash for later use.

Here's what I am doing basically.

  is required 'active_support' @emailhash = hash.new email = email.find (all) email. Email | Email | Email.attributes.keys.each do | @column | | @EMailhash [email.ticketno] || Hash.new @ melehash [email.ticketno] = email @ End of the column end  

The row that does not work:

  @emailhash [Email.ticketno] = Email @ Column  

Is there a way that I can do it properly? Basically my goal is to make a hash off values ​​stored in the table column, any input is appreciated.

  • Ruby programmer usually indents 2
  • Your code will display all e- Squash all the emails in any entry instead of mail
  • If you want to call a method dynamically, use Object.send .
  • @emailhash [email.ticketno] || Hash New does nothing.
  • Something like this can happen:

      is required 'active_support' @emailhash = {} Email.find (: all) .each do | Email | @mailhash [email.ticketno] = {} email.attributes.keys.each do | Key | @EMailhash [email.ticketno] [key] = "email.send" end of end  

    key "send", which calls the method identified by string or symbol is. / P>


    Comments

    Popular posts from this blog

    oracle - The fastest way to check if some records in a database table? -

    php - multilevel menu with multilevel array -

    jQuery UI: Datepicker month format -