nested-forms

Rails forms for has_many through association with additional attributes?

元气小坏坏 提交于 2019-11-27 05:30:30
问题 How can I generate form fields for a has_many :through association that has additional attributes? The has_many :through relationship has an additional column called weight . Here's the migration file for the join table: create_table :users_widgets do |t| t.integer :user_id t.integer :widget_id t.integer :weight t.timestamps end The models look like this: User has_many :widgets, :through => :users_widgets, :class_name => 'Widget', :source => :widget has_many :users_widgets accepts_nested

Rails has_many :through nested form

走远了吗. 提交于 2019-11-27 04:18:04
问题 I have just jumped into has_many :through association. I'm trying to implement the ability to save data for all 3 tables ( Physician , Patient and association table) through a single form. My migrations: class CreatePhysicians < ActiveRecord::Migration def self.up create_table :physicians do |t| t.string :name t.timestamps end end end class CreatePatients < ActiveRecord::Migration def self.up create_table :patients do |t| t.string :name t.timestamps end end end class CreateAppointments <

Rails 4 nested attributes not saving

跟風遠走 提交于 2019-11-27 02:18:14
问题 I cannot seem to get nested attributes to save to the database. I am using Rails 4. Here are my models : class Answer < ActiveRecord::Base belongs_to :question end class Question < ActiveRecord::Base has_many :answers belongs_to :survey accepts_nested_attributes_for :answers, allow_destroy: true end class Survey < ActiveRecord::Base has_many :questions validates_presence_of :name accepts_nested_attributes_for :questions end Here is the controller: def create @survey = Survey.new(survey_params

has_many :through nested_form that can build multiple instances

家住魔仙堡 提交于 2019-11-26 21:26:12
问题 I have the following code in my models: Class Farm < ActiveRecord::Base has_many :farm_products, :dependent => :destroy has_many :products, :through => :farm_products accepts_nested_attributes_for :farm_products end class Product < ActiveRecord::Base has_many :farm_products, :dependent => :destroy has_many :farms, :through => :farm_products end class FarmProduct < ActiveRecord::Base belongs_to :farm belongs_to :product end I have a form to create a new Farm, and I want to create farm_products

Use rails nested model to *create* outer object and simultaneously *edit* existing nested object?

旧巷老猫 提交于 2019-11-26 19:15:30
问题 Using Rails 2.3.8 Goal is to create a Blogger while simultaneously updating the nested User model (in case info has changed, etc.), OR create a brand new user if it doesn't exist yet. Model: class Blogger < ActiveRecord::Base belongs_to :user accepts_nested_attributes_for :user end Blogger controller: def new @blogger = Blogger.new if user = self.get_user_from_session @blogger.user = user else @blogger.build_user end # get_user_from_session returns existing user # saved in session (if there

validates_uniqueness_of in destroyed nested model rails

不羁的心 提交于 2019-11-26 19:09:43
问题 I have a Project model which accepts nested attributes for Task. class Project < ActiveRecord::Base has_many :tasks accepts_nested_attributes_for :tasks, :allow_destroy => :true end class Task < ActiveRecord::Base validates_uniqueness_of :name end Uniqueness validation in Task model gives problem while updating Project. In edit of project i delete a task T1 and then add a new task with same name T1, uniqueness validation restricts the saving of Project. params hash look something like task

Rails 4.0 with Devise. Nested attributes Unpermited parameters

筅森魡賤 提交于 2019-11-26 09:29:14
问题 I am working on a web-app using Devise and Rails 4. I have a User model which I have extended with 2 extra form fields such that when a user signs up he can also submit his first/last names. (based on http://blog.12spokes.com/web-design-development/adding-custom-fields-to-your-devise-user-model-in-rails-4/). I now want to add a Institution model. This model has_many :users, and a user belongs_to :institution. I want to be able to register the institution\'s name on the same form I register

Rails nested form with has_many :through, how to edit attributes of join model?

只谈情不闲聊 提交于 2019-11-26 01:04:13
问题 How do you edit the attributes of a join model when using accepts_nested_attributes_for? I have 3 models: Topics and Articles joined by Linkers class Topic < ActiveRecord::Base has_many :linkers has_many :articles, :through => :linkers, :foreign_key => :article_id accepts_nested_attributes_for :articles end class Article < ActiveRecord::Base has_many :linkers has_many :topics, :through => :linkers, :foreign_key => :topic_id end class Linker < ActiveRecord::Base #this is the join model, has

Can you nest html forms?

穿精又带淫゛_ 提交于 2019-11-25 23:56:26
问题 Is it possible to nest html forms like this <form name=\"mainForm\"> <form name=\"subForm\"> </form> </form> so that both forms work? My friend is having problems with this, a part of the subForm works, while another part of it does not. 回答1: In a word, no. You can have several forms in a page but they should not be nested. From the html5 working draft: 4.10.3 The form element Content model: Flow content, but with no form element descendants. 回答2: The second form will be ignored, see the