Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8849935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:46:57+00:00 2026-06-14T12:46:57+00:00

Is posible send more than one format, something like: <%= form_for(@post, :format => :json,

  • 0

Is posible send more than one format, something like:

<%= form_for(@post, :format => :json, :csv, :xml) do |f| %>
  ...
<% end %>

Thank you very much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:46:58+00:00Added an answer on June 14, 2026 at 12:46 pm

    You don’t “send a format”, you send a request to the server, which responds to this request in the specified format. You can use a parameter to tell the controller which format you want it to return.

    There are several ways to tell the controller which format you want. Actually there’s only one way, passing a parameter, but there are several ways to pass this parameter.

    I like the hidden_field method, in which you add a hidden field with the value being the format you want, and change the value of this field using javascript when a user selects a radio button with the format, for example. You can also do this using more than 1 submit button, and having the HTML onClick attribute set to a function that changes the value of the hidden_field.

    Example (I’ll use the multi-button method, and use jQuery):

    First, let’s build the form:

    <%= form_for(@post, :format => :json, :csv, :xml) do |f| %>
    
    ...
    
    <%= f.hidden_field :random_param_name, :value => "default format value" %>
    
    // Notice you should use f.submit here instead of button_tag, because it's a form_for, not a form_tag
    
    <%= f.submit "Give me XML!", :onClick => "changeFormat('xml');" %>
    <%= f.submit "Give me JSON!", :onClick => "changeFormat('json');" %>
    <%= f.submit "Give me CSV!", :onClick => "changeFormat('csv');" %>
    
    <% end %>
    

    Now we add the changeFormat function:

    <script type="text/javascript">
        function changeFormat(format) {
            // The ID here is in the format "model_name_field_name". This is default for any form_for.
            $("#post_random_param_name").val(format);
        }
    </script>
    

    Now you just need to catch this parameter in the controller (params[:post][:random_param_name]) and do what you have to do! One last thing you need to do is adding this random_param_name to the accessible attributes of the Post model:

    attr_accessor :random_param_name
    attr_accessible :random_param_name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is possible to create more than one email profile on email router in Dynamic
I am developing a multiplayer game with more than 2 players. I would like
Can I send a SelectList through a Data Annotation? Something like... [UIHint(DropDownList, , new
Does anybody know, If it's possible, and how to send SMS to more than
Is it possible to send pre-compressed files that are contained within an EARfile? More
Is it possible to send an intent only to one service when this one
While I do understand php, I'm more of a sysadmin than a programmer. Add
We have some standalone devices that will send XML messages to arbitrary processing software
I'm working with a standard post/comments system where one member writes a post and
I've been looking for this for more than a week, and I haven't been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.