request: /blog
controller placed at /app/controllers/test/blog_controller.rb:
class Test::BlogController < ApplicationController
def index
render :text => ‘Hello, World!’
end
end
What the write map.connect shoud I use? Any Idias?
I see that map.connect ‘/blog’, :controller => ‘test/blog’ working
correctly, but what about more complex example such a map.connect
':controller/:action/:id?
I see that map.connect ‘/blog’, :controller => ‘test/blog’ working
correctly, but what about more complex example such a map.connect
':controller/:action/:id?
Addresses[0].attributes.keys returns the columns, but not in the selected
order
Addresses.column_names returns the column in alphabetical order.
Any suggestions?
columns = %w( name street city state zip )
sql = <<-sql
select #{ columns.join ', ' }
from addresses
sql
addresses = address.find_by_sql sql
csv = CSV::Writer::new ‘somefile.csv’
csv << columns # add header
addresses.each do |address|
row = columns.map{|col| address.send col}
csv << row
end
hth.
-a
===============================================================================
| ara [dot] t [dot] howard [at] noaa [dot] gov
| all happiness comes from the desire for others to be happy. all misery
| comes from the desire for oneself to be happy.
| – bodhicaryavatara
I have written some reporting queries using Active Record such as:
addresses = address.find_by_sql(“select name, street, city, state, zip
from
address”)
The queries are actually much more complex than this with aggregation,
joins, etc… that’s why I’m using the find_by_sql method.
I am converting the output of my report queries to CSV… unfortunately
I
can’t figure out a generic way to get the report queries to preserve the
column order (name, stree, city, zip)
Addresses[0].attributes.keys returns the columns, but not in the
selected
order
Addresses.column_names returns the column in alphabetical order.
Any suggestions?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.