nested-forms

Rails - User Input for Multiple models on a single form - How

好久不见. 提交于 2019-11-27 19:08:36
This is basically a nested form question, albeit with only one field that belongs to a parent model. My data entry form collects data for a model - however I also need to collect one other a data element/value (UserID) that actually goes into a parent record that will be created with the detail record. AFAIK Rails expects each form field to map to a model and I need to create an unbound data input field that I will use separately. How can I override this default behaviour and create a'free form/unbound field'? TIA, BC Heres something from my own app: Access it by: params[:company] and params[

Rails has_many :through nested form

江枫思渺然 提交于 2019-11-27 18:49:15
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 < ActiveRecord::Migration def self.up create_table :appointments do |t| t.integer :physician_id t.integer

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

放肆的年华 提交于 2019-11-27 17:53:43
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 is one) end def create @blogger = Blogger.new(params[:blogger]) # ... end Form: <% form_for(@blogger) do

validates_uniqueness_of in destroyed nested model rails

不羁的心 提交于 2019-11-27 17:45:12
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_attributes => { {"id" => "1","name" => "T1", "_destroy" => "1"},{"name" => "T1"}} Validation on task is

Error in slick.js: “Uncaught TypeError: Cannot read property 'add' of null”

守給你的承諾、 提交于 2019-11-27 13:42:06
问题 I used slick js for slider view of image. Here is my code. <div class="slider_wrap add-remove"> <%= f.fields_for :images do |image_form| %> <%#= render 'images_fields', :f => image_form %> <div> <%= image_tag image_form.object.picture.url,:class=>"drop_down_link even img_prev" %> </div> <div class="image_upload_div"> <div class="image-upload"> <label> <i class="fa fa-cloud-upload"> <%= image_form.file_field :picture ,:'data-role'=>"none",:onchange=>"readURL(this);" , :accept => 'image/jpeg ,

Rails 3, nested multi-level forms and has_many through

≡放荡痞女 提交于 2019-11-27 10:11:50
问题 I'm trying to get it to work but it dosen't! I have class User < ActiveRecord::Base has_many :events, :through => :event_users has_many :event_users accepts_nested_attributes_for :event_users end class Event < ActiveRecord::Base has_many :event_users has_many :users, :through => :event_users accepts_nested_attributes_for :users end class EventUser < ActiveRecord::Base set_table_name :events_users belongs_to :event belongs_to :user accepts_nested_attributes_for :events accepts_nested

symfony2 multiple nested forms prototype

≯℡__Kan透↙ 提交于 2019-11-27 09:18:10
问题 I want to include a collection type inside another collection type. It should look like this: Using just one collection works fine, but I need to edit the prototype of the outer form, so it renders the prototype of the inner form for each line. Any ideas how could I do that? Also what would be the best way to save EDIT: Now I am trying to render the prototype of the nested form: <ul class="characteristics-container" data-prototype="{{ form_widget(form.characteristics.vars.prototype)|e }}"

Nested paperclip form with multiple images

对着背影说爱祢 提交于 2019-11-27 07:04:44
问题 I have a one-to-many association between a Banana model and an Image model. In addition, each Banana and Image belong to a User (via a separate association because an Image and its Banana might have different Users). I would like a nested form to create Bananas as well as Images. The kicker is that I don't know how many Images to build (note the multiple attribute). The commented out bit of the form below will create the appropriate amount of Images, but won't complete the associated User

Rails has_many through form with checkboxes and extra field in the join model

安稳与你 提交于 2019-11-27 06:55:52
I'm trying to solve a pretty common (as I thought) task. There're three models: class Product < ActiveRecord::Base validates :name, presence: true has_many :categorizations has_many :categories, :through => :categorizations accepts_nested_attributes_for :categorizations end class Categorization < ActiveRecord::Base belongs_to :product belongs_to :category validates :description, presence: true # note the additional field here end class Category < ActiveRecord::Base validates :name, presence: true end My problems begin when it comes to Product new/edit form. When creating a product I need to

Rails 4: accepts_nested_attributes_for and mass assignment

流过昼夜 提交于 2019-11-27 06:05:04
问题 I am trying to reproduce railscast #196 in Rails 4. However, I'm experiencing some problems. In my example I try to generate a Phonebook - each Person could have multiple PhoneNumbers These are important parts of my controller: class PeopleController < ApplicationController def new @person = Person.new 3.times{ @person.phones.build } end def create @person = Person.create(person_params) @person.phones.build(params[:person][:phones]) redirect_to people_path end private def person_params params