dennismonsewicz
dennismonsewicz

Reputation: 25542

Rails 3 render problems

I am writing a script that allows for a user to pass a format via a URL parameter. I have JSON and XML working as needed, but I can't get YAML working.

case params[:format]
        when "xml" then respond_with(@labels)
        when "json" then respond_with(@labels_hash.to_json)
        when "yaml" then render :text => @labels_hash.to_yaml
      end

For some reason when I pass the format=yaml in my URL then my script tries to force download a file. Any reason why this would happen?

Working Code:

case params[:format]
        when "xml" then respond_with(@labels)
        when "json" then respond_with(@labels_hash.to_json)
        when "yaml" then respond_with(@labels_hash) do |format|
          format.yaml { render :text => @labels_hash.to_s }
        end
      end

Upvotes: 0

Views: 785

Answers (1)

Zabba
Zabba

Reputation: 65497

Try:

Adding :yaml to respond_to :yaml in the controller, and :

respond_to do |format|
  ....other formats....
  format.yaml { render :yaml => @labels_hash }
end

Upvotes: 1

Related Questions