nested-forms

Cannot get nested form with a has_one association to work

坚强是说给别人听的谎言 提交于 2020-01-03 17:36:39
问题 I have these models: class User < ActiveRecord::Base has_one :city accepts_nested_attributes_for :city end class City < ActiveRecord::Base belongs_to :user end This controller action: def create @user = User.new(params[:user]) respond_to do |format| if @user.save format.html { redirect_to(@user, :notice => 'User was successfully created.') } format.xml { render :xml => @user, :status => :created, :location => @user } else format.html { render :action => "new" } format.xml { render :xml =>

Cannot get nested form with a has_one association to work

风格不统一 提交于 2020-01-03 17:36:13
问题 I have these models: class User < ActiveRecord::Base has_one :city accepts_nested_attributes_for :city end class City < ActiveRecord::Base belongs_to :user end This controller action: def create @user = User.new(params[:user]) respond_to do |format| if @user.save format.html { redirect_to(@user, :notice => 'User was successfully created.') } format.xml { render :xml => @user, :status => :created, :location => @user } else format.html { render :action => "new" } format.xml { render :xml =>

Nested table formatting with simple_form, nested_form and twitter-bootstrap

旧巷老猫 提交于 2020-01-03 09:12:11
问题 Update: I updated this after doing some digging and realizing that this might be twitter-bootstrap causing the problem. Here is a rough version of my nested form: <%= simple_nested_form_for @user, :html => { :class => 'form-horizontal' } do |f| %> <fieldset> <%= f.input :email %> <%= f.input :name_first %> <%= f.input :name_last %> <table class="table table-striped"> <thead> <tr> <th>Active</th> <th>Company</th> <th>Role</th> <th>Actions</th> </tr> </thead> <tbody> <%= f.simple_fields_for

Having an error with nested forms with Mongoid

坚强是说给别人听的谎言 提交于 2020-01-03 06:27:40
问题 I am using Mongoid on Rails 3 and trying to build a nested form. The problem I run into is when I used accept_nested_attributes_for method, I get this error message: undefined method `persisted?' for []:Array Is anyone else having problem with nested forms in Mongoid? What can I do to fix it? Edit: more about the error. This is the full trace. mongoid (2.0.0.beta.19) lib/mongoid/criteria.rb:156:in `send' mongoid (2.0.0.beta.19) lib/mongoid/criteria.rb:156:in `method_missing' mongoid (2.0.0

Turning a calendar into a form using Rails?

时光毁灭记忆、已成空白 提交于 2020-01-02 19:12:34
问题 Question : How do I turn a calendar into a form where the dateselect is rendered to match the calendar day instead of the current date? What I'm trying to do: I'd like to create a calendar that displays the cyclist's workouts. Create workouts within each calendar day, automatically rendering the workoutdate that matches the given day in the form Each workout has many intervals. Each calendar day has one workout. Plugins: Extracted the table_builder.rb and calendar_helper.rb from https:/

Turning a calendar into a form using Rails?

一世执手 提交于 2020-01-02 19:12:27
问题 Question : How do I turn a calendar into a form where the dateselect is rendered to match the calendar day instead of the current date? What I'm trying to do: I'd like to create a calendar that displays the cyclist's workouts. Create workouts within each calendar day, automatically rendering the workoutdate that matches the given day in the form Each workout has many intervals. Each calendar day has one workout. Plugins: Extracted the table_builder.rb and calendar_helper.rb from https:/

nested_form, collection_select, accepts_nested_attributes_for and fields_for, and adding records to a join table

大憨熊 提交于 2020-01-01 19:13:33
问题 Update: according to the stack trace, posted at the end of this question, I think the real problem is to figure out what attr_accessible and build association settings I need to get the contributors and linkers attributes to update with the new isbn id. Please help me! Following on from this question... I've got a join table between two models - isbns and contributors - which have a many to many relationship. I want to use the existing values from the contributor model in a collection_select

nested_form, collection_select, accepts_nested_attributes_for and fields_for, and adding records to a join table

本秂侑毒 提交于 2020-01-01 19:13:12
问题 Update: according to the stack trace, posted at the end of this question, I think the real problem is to figure out what attr_accessible and build association settings I need to get the contributors and linkers attributes to update with the new isbn id. Please help me! Following on from this question... I've got a join table between two models - isbns and contributors - which have a many to many relationship. I want to use the existing values from the contributor model in a collection_select

Nested Model Forms - Railscast #196 revised - Adding fields via jQuery not working

不打扰是莪最后的温柔 提交于 2020-01-01 14:36:01
问题 I was following the Railscast #196 revised and everything went basically fine, but I am not able to add new fields to the nested form. The "remove fields" function works nicely, but after click on "link_to_add_fields", the browser jumps to the top of the page, and no new field appears. There are already a ton of questions to this railscast, like here or here, and I tried to read all of them, but most of them are referring to the original casts from 2010. I am stuck for hours now, and I can't

Nested Forms Rails

我只是一个虾纸丫 提交于 2020-01-01 12:33:09
问题 I have 2 models User and Address . class User < ActiveRecord::Base has_many :addresses accepts_nested_attributes_for :addresses end class Address < ActiveRecord::Base belongs_to :user end My controller def new @user = User.new @user.addresses << Address.new @user.addresses << Address.new end def create @user = User.new(params[:user]) if @user.save #do something else render 'new' end end And my View <%= form_for @user do |f| %> <%= f.label :name %> <%= f.text_field :name %> <%= f.fields_for