Check that returns csv

I would a checkbox that when check will return csv and html if otherwise. I follow this video and got the csv to work http://railscasts.com/episodes/362-exporting-csv-and-excel?autoplay=true

now I have a check_box_tag that is to be submitted with the form. if the check box is checked then it should render the csv.

=form_tag exams_path, method: :get do
  =text_field_tag :search, params[:search]
  =check_box_tag "csv"
  = submit_tag "Search by id", name: nil

Inside the controller it have

...
params[:format] = "csv" if params[:csv]
respond_to do |format|
  format.html
  format.csv {render text:@exams.to_csv}
end
...

but this does not work.

Answers


I figure it out thanks to John.

I need:

request.format = :csv if params[:csv]

instead of my original

params[:format] = "csv" if params[:csv]

Dont know if changing format is the best way to go, but it just what I need.


Need Your Help

How can I make the HTML5 canvas go fullscreen?

javascript html5 canvas html5-canvas fullscreen

I have seen dozens of tutorials on this, and it seems straight forward. All I want is to make my HTML5 canvas element go full-screen (as in total full-screen, taking up the whole monitor).

How to programmatically trigger password reset email in django 1.7.6?

python django passwords reset programmatically-created

I've encountered a problem where I had to load more than 200 new users into my django app and right away send them a password reset email. This had to happen only once, done only by me and run quie...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.