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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:51:41+00:00 2026-06-17T05:51:41+00:00

I am not sure how to proper create a rails form with nested form.

  • 0

I am not sure how to proper create a rails form with nested form. I have followed many tutorial but becoming more confused has in what should it be, singular plurials, controller… Here my models

model/event.rb

  attr_accessible :description :title, :tag_ids, :locations_attributes
  has_many :location
  accepts_nested_attributes_for :location, :allow_destroy => true

model/location.rb

  attr_accessible :address, :customer_id, :event_id, :latitude, :longitude
  belongs_to :customer
  belongs_to :event

controller.rb

  def new
    @event = Event.new
    ...
  def create
    @event = Event.new(params[:event])
    ...

view form.html.erb

<%= form_for(@event) do |f| %>
  <%= f.fields_for :locations do |e| %>
    <%= e.text_field :longitude %>
    <%= e.text_field :latitude %>
  <% end %>
  ...
<% end %>

error

Can't mass-assign protected attributes: locations

params send

 "locations"=>{"longitude"=>"45.6666",
 "latitude"=>"47.44444665"},

Either my relationship are wrong because fields_for doesn’t support it, either my controller is not proper, or either rails is just not a great language, or i don’t understand it anymore.

  • 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-17T05:51:42+00:00Added an answer on June 17, 2026 at 5:51 am

    You.re nearly there…

    event.rb – locations NOT location

    attr_accessible :description :title, :tag_ids, :locations_attributes
    has_many :locations
    accepts_nested_attributes_for :locations, :allow_destroy => true
    

    Should do it I think

    edit

    And as Valery Kvon says, you need to add

    @event.locations.build
    

    to your controller

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

Sidebar

Related Questions

I'm not sure what the proper syntax for using C enums is. I have
I'm just not too sure the proper way of doing this. I basically have
Not sure how to ask this, but i'll give it a try: I have
First off I'm not sure that's the proper title for this question but hopefully
I'm not sure how to proper name the question. Please fell free do edit.
I'm not sure if there is a proper term for what I want to
Wikipedia: Directed Acyclic Graph Not sure if leaf node is still proper terminology since
First of all I'm not sure if .exe window is the proper term. It's
Would this be a proper way to dispose of a BackGroundWorker? I'm not sure
Not sure if im just being stupid or something but here goes i work

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.