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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:04:13+00:00 2026-05-26T06:04:13+00:00

I have a nested form ,and i want to include city_id in the stores

  • 0

I have a nested form ,and i want to include city_id in the stores model,is this <%= s.hidden_field :city_id, @city.id %> correct? If yes what do i add in the controller after that? If it is not a correct way to include it can anybody show me the right way please? Much thanks.

<%= form_for @deal ,:url=>{:action =>"create"} do |c|%>
  <%= c.text_field :item_name %>
  <%= c.text_field :price %>

  <%=c.fields_for :stores do |s| %>
    <%=s.text_field :store_name %>
    <%= s.hidden_field :city_id, @city.id %>
    <%=s.text_field :address %>
  <%end%>           

  <%= c.submit "post"%>     
<%end%>

controller

def create
  @city = City.find(session[:city_id])
  @deal=@city.deals.build(params[:deal])

  if @deal.save
    redirect_to @deal
    flash[:notice]="successfully created"
  else
    render 'new' 
  end 
end

models

class City < ActiveRecord::Base
    has_many :stores
    has_many :deals 
end

class Deal < ActiveRecord::Base
    belongs_to :city
    has_many :stores ,:through =>:store_deals
    has_many :store_deals
end

class StoreDeal < ActiveRecord::Base
    belongs_to :store
    belongs_to :deal
end

error

NoMethodError in Deal#new

Showing /home/Deals/app/views/deal/new.html.erb where line #13 raised:

undefined method `merge' for 2:Fixnum
Extracted source (around line #13):

10: <tr><td><label>Price</label></td><td><%= c.text_field :price %></td></tr>
11: <%=c.fields_for :stores do |s| %>
12: <tr><td><label>Store</label></td><td><%=s.text_field :store_name %></td></tr>
13: <%= s.hidden_field :city_id, @city.id %>
14: <tr><td><label>Cross street</label></td><td><%=s.text_field :address %></td></tr>
15: <%end%>
16: <tr><td><%= c.submit "post"%></td></tr>
  • 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-26T06:04:13+00:00Added an answer on May 26, 2026 at 6:04 am

    Okay, now that I’ve looked over your code more carefully and seen the it’s clear what the problem is. The hidden_field helper doesn’t have value as one of its arguments. Use:

    <%= s.hidden_field :city_id, :value => @city.id %>
    

    However, for the reason Michael Durrant points out, it would be better to handle this in your controller.

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

Sidebar

Related Questions

I'm following this rails cast to create a nested form: http://railscasts.com/episodes/196-nested-model-form-part-1 I have a
I have a nested json. I want to post it as a form input
I have a nested form Parent, which accepts attribute for Child. In my controller#new,
I have a nested form with 3 related models. I want all the fields
I have a nested form categories for stores resource. They have a has_and_belongs_to_many relationship.
I am following the Rails guide for doing multi-model nested form. I have 2
I followed the instructions in Railscasts #197 http://railscasts.com/episodes/197-nested-model-form-part-2 about how to add links that
I have a comment controller that uses a form partial to add comments. Now
I want to scrape some html pages that have nested form elements with lxml.
I have a nested form and once I save, I want to be able

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.