I accidentally posted this to the "Ruby" forum when it should have gone
here -- sorry.
I am using *_path in views and *_url in controllers (with redirect_to,
for example). It is my understanding that this is generally considered
a good practice.
I want to use my app using https, and thought it would work that way as
long as I loaded the app by browsing to https://my.app.com. However, it
appears that even if I do this, redirect_to some_model_url generates a
url with a protocol of https://.
How do I get *_url to generate a url with https:// for the protocol?
I accidentally posted this to the "Ruby" forum when it should have gone
here -- sorry.
I am using *_path in views and *_url in controllers (with redirect_to,
for example). It is my understanding that this is generally considered
a good practice.
I want to use my app using https, and thought it would work that way as
long as I loaded the app by browsing to https://my.app.com. However, it
appears that even if I do this, redirect_to some_model_url generates a
url with a protocol of https://.
I assume you meant to say "http://" ?
How do I get *_url to generate a url with https:// for the protocol?
How do I get *_url to generate a url with https:// for the protocol?
some_model_url(:scheme => 'https')
Thanks for the response. I guess I was looking for a way to do this
application-wide. It would not be very DRY to have to add (:scheme =>
'https') to every place in my app where I call a *_url helper.
Use *_path? I do it and haven't seen any browsers complain about the
redirects...
Again, that would mean going through the entire application and changing
every reference.
Besides, using relative paths in redirects violates the HTTP spec. I
understand that it gets the job done, but that doesn't seem like the
right way to do it.
I don't wish to appear argumentative, but I really hope somebody knows a
cleaner way to do this.
Use *_path? I do it and haven't seen any browsers complain about the
redirects...
Again, that would mean going through the entire application and changing
every reference.
Besides, using relative paths in redirects violates the HTTP spec. I
understand that it gets the job done, but that doesn't seem like the
right way to do it.
I don't wish to appear argumentative, but I really hope somebody knows a
cleaner way to do this.
If you want to pull out data in csv format from an existing mysql
database using Rails, this is the easiest way to do it :
1. install fastercsv : sudo gem install fastercsv
2. Add on top of your controller : require 'fastercsv'
3. Create an action in your controller and its corresponding view
# The action
def import_csv
result = YourModel.find(:all, :conditions => "your_condition")
@outfile = "your_csv_report_name_" + Time.now.strftime("%m-%d-%Y") +
".csv"
csv_data = FasterCSV.generate do |csv|
#field names
csv << ["Field_name_1"]
csv << ["Field_name_2"]
#Data
result.each do |table|
csv << [ table.field1 table.field2]
end
#Write data in csv format
send_data csv_data,
:type => 'text/csv; charset=iso-8859-1; header=present',
:disposition => "attachment; filename=#{@outfile}"
redirect_to :action => "your_action"
end
end
#The view
<% form_tag :action => "import_csv" do %>
<%= submit_tag 'Import CSV' %>
<% end %>