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 7767155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:36:18+00:00 2026-06-01T15:36:18+00:00

I’ve been on this for over a day now and I hope someone can

  • 0

I’ve been on this for over a day now and I hope someone can help me out. I’m new to ruby/rails and I think I’m getting close.

I have a view whereas you can input basic information about an apartment such as unit number, rate, if it is enabled. You can then enter how many apartments you want to create. This information is placed into session variables and a preview form is shown. So for example if you had entered 5 for the number of apartments you wanted to create you would get 5 rows in a table, each with a heading of Unit Number, Rate, and Enabled. You could then make modifications as needed to any individual apartments and click on Save.

/app/models/apartment.rb

def preview
  @count = session['count'].to_i
    @mktg_apartment = []
    1.upto(@count) do |i|
    @mktg_apartment[i] = Apartment.new
    @mktg_apartment[i].rate = session['tmp_rate']
    @mktg_apartment[i].enabled = true
  end
end

/app/views/preview.html.haml

=form_for @mktg_apartment, :url => {:action => 'save_preview', :method => 'post'} do
  - 1.upto(@count) do |x|
    text_field "mktg_apartment[#{x}]", :unit
    text_field "mktg_apartment[#{x}]", :rate
    text_field "mktg_apartment[#{x}]", :enabled

I don’t really have my save method created yet. I will put out what I have, at one point it would save only the last record entered, but I know it’s all wrong at this point.

/app/model/apartment.rb

def save_preview
  @mktg_apartment = Mktg::Apartment.new(params[:mktg_apartment])
  respond_to do |format|
    if @mktg_apartment.save
      format.html { redirect_to mktg_apartments_path }
    else
      format.html { render action: "preview" }
    end
  end
end

In my preview.html.haml form I dumped @mktg_apartment and see the following:

[nil, #<Mktg::Apartment id: nil, created_at: nil, updated_at: nil, unit: nil, rate: 1222.0, enabled: true>, 
#<Mktg::Apartment id: nil, created_at: nil, updated_at: nil, unit: nil, rate: 1222.0, enabled: true>,
#<Mktg::Apartment id: nil, created_at: nil, updated_at: nil, unit: nil, rate: 1222.0, enabled: true>,
#<Mktg::Apartment id: nil, created_at: nil, updated_at: nil, unit: nil, rate: 1222.0, enabled: true>,
#<Mktg::Apartment id: nil, created_at: nil, updated_at: nil, unit: nil, rate: 1222.0, enabled: true>]

When I hit save it errors out and I see the following parameters being passed to my post form:

{"utf8"=>"✓",
"authenticity_token"=>"iGLdu/ZmulcLp4xZEU4a4iuxWV1opzNIyXcnZEQCtj8=",
"mktg_apartment"=>{"1"=>{"unit"=>"",
"rate"=>"",
"enabled"=>"0"},
"2"=>{"unit"=>"",
"rate"=>"",
"enabled"=>"0"},
"3"=>{"unit"=>"",
"rate"=>"",
"enabled"=>"0"},
"4"=>{"unit"=>"",
"rate"=>"",
"enabled"=>"0"},
"5"=>{"unit"=>"",
"rate"=>"",
"enabled"=>"0"}},
"commit"=>"Save",
"method"=>"post"}

So it looks like however I’m setting up the array of @mktg_apartment in my preview method is not being accessed correctly in my preview view. It actually looks like my preview view is passing the parameters as I would expect to the save_preview post method.

Any help please, I’m beating my head against the wall. Thank you…

  • 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-01T15:36:20+00:00Added an answer on June 1, 2026 at 3:36 pm

    I would use a nested form. Split the units into a separate model and have something like block of land (block) has many units. Then you could enter all the information using a complex form.

    Refer: http://railscasts.com/episodes/196-nested-model-form-part-1

    The block model could hold the size of the entire block and a unit model can hold the particulars about the specific unit.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported

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.