I am new to rails as well, so you might take my advise with a grain of
salt, but I needed a similar feature myself this very evening so I
found a method of adding the following to a method in one of your
controllers:

    headers['Content-Type'] = "application/vnd.ms-excel"
    headers['Content-Disposition'] = 'attachment;
filename="report.xls"'
    headers['Cache-Control'] = ''

Then in the corresponding view you simply put a table with all your
data in it.. for example:

<table border="1">
  <tr>
    <th>First Name</th><th>Last Name</th>
  </tr>
  <% @user.each do |u| %>
  <tr>
   <td><%= user.firstname %></td><td><%= user.lastname %></td>
  <% end %>
 </tr>
</table>

When you visit that page it will promt for a download.. so if you were
to simply link to that page it would bring up a download prompt.

Its quick and dirty.. but I have no idea if it is the best way to do
it!

Aaron

On May 26, 4:10 pm, Peter Bell <[email protected]> wrote:
> Hi Guys,
>
> Still fairly new to Rails. Want to see if I'm doing anything un-idiomatic. 
> Few questions of style:
>
> 1. "public controller"
> I'm using a "public" controller. It seems to be a good semantic choice, 
> because it's for the landing page and the other few pages that public site 
> visitors go to. I see "home" more often, but while home is meaningful for the 
> landing page, it doesn't seem a great word to describe the collection of 
> pages accessible to site visitors who have not registered (/, about_us, 
> tesrms_and_conditions, etc), hence my choice of "public" which seems to 
> better fit what I'm trying to express. Weird or just different?
>
> 2. rspec view naming
> I know the default naming convention for a views/public/landing.html.erb is 
> spec/views/public/landing.html.erb_spec.rb
> This seems like a bad idea. I don't want to test that it's an erb file - I 
> want to test that the landing.html page contains whatever I want it to 
> contain. So if I move from erb to haml that should not require me to rewrite 
> or rename my test. As such, a better convention seems to be: 
> spec/views/public/landing.html_spec.rb
>
> Any thoughts/opinions? I know it's small stuff, but I'm trying to balance 
> idioms with standard best practices with what seems to me to be the most 
> readable and DRYest approach to writing the code.
>
> Best Wishes,
> Peter

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to