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

  • Home
  • SEARCH
  • 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 3324428
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:25:13+00:00 2026-05-17T23:25:13+00:00

i have a form_for code <%form_for :a,:url=>{:controller=>biz/a,:action=>save},:html =>{:multipart => true} do |f| %> …..

  • 0

i have a form_for code

<%form_for :a,:url=>{:controller=>"biz/a",:action=>"save"},:html =>{:multipart => true} do |f| %>
.....
<%f.fields_for :b do |b|%>
.....
<%b.fields_for :apples  do |apple|%>
...
<%end%>
....
<%end%>

it outputs the html code without fields_for function

<textarea cols="40" id="a_b_apples_content" name="a[b][apples][content]" rows="20" style="width:500px;height:100px;border:1px #889BAA solid;color:#999;font-size:12px;padding:6px;"></textarea>

when i change the form_for to :

<%form_for @a,:url=>{:controller=>"biz/a",:action=>"save"},:html =>{:multipart => true} do |f| %>

it just work fine.
And it outputs:

<textarea cols="40" id="a_b_apples_content" name="a[b_attributes][apples_attributes][0][content]" rows="20" style="width:500px;height:100px;border:1px #889BAA solid;color:#999;font-size:12px;padding:6px;"></textarea>

as i want.
why dont the symbol in form_for work fine?what’s difference between :a and @a in form_for.
Thanks.
I use rails 2.3.8 , ruby 1.8.7,chrome web browser.

  • 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-05-17T23:25:13+00:00Added an answer on May 17, 2026 at 11:25 pm

    This is a common source of frustration. form_for actually behaves differently based on whether you pass it a symbol or an object. If you pass it a symbol, like so:

    <% form_for :person do |f| %>
      <% f.text_field :name %>
    <% end %>
    

    Then the form builder will work, but it will only setup the param values, and load the default values if @person exists. Your parmas hash will look like it should:

    params = {
      :person => {
        :name => 'bob'
      }
    }
    

    But it won’t setup your route properly. It’ll assume you want to submit to the same page you’re already on. Now if you give it an object, form_for will do much more for you. It will check to see if this object is new, or being updated, and it will set the form tag’s parameters accordingly, along with some other benefits.

    Honestly, I can’t tell you why they behave differently. The symbol version obviously still has access to the instance variable (@person in the example above) because the fields will be populated with their existing values. The easy solution is that passing an instance variable is always the way to go, and will work correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a nested form (using accepts_nested_attributes_for in respective models): <%= form_for(:technician, :url =>
I have a model (Project), in the 'new' action I have this code <h1>Create
I have a model (Project), in the 'new' action I have this code <h1>Create
In my views.py, i have a snippit of code like this: def clean_post_data(form): for
We have a simple registration form for our website users where we only require
Form validation for check boxes only seems to be working in IE....? Anyone have
I have a form that has multiple fields, and for testing purposes is there
I have a form which has a lot of SELECTs. For various reasons, I'd
In good old MFC, the DDX routines would have built in validation for form
I have a website form that requires a US phone number input for follow

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.