nested-forms

Validating uniqueness of nested data. Using cocoon gem

痴心易碎 提交于 2020-01-06 20:05:38
问题 I currently have a Client model that has_many pricings. Pricings table: create_table "pricings", force: true do |t| t.integer "product_id" t.integer "client_id" t.decimal "unit_price" t.datetime "created_at" t.datetime "updated_at" end Pricings model: class Pricing < ActiveRecord::Base belongs_to :client belongs_to :product validates :unit_price, presence: true end Client model: class Client < ActiveRecord::Base has_many :deliveries has_many :collections has_many :pricings accepts_nested

Validating uniqueness of nested data. Using cocoon gem

淺唱寂寞╮ 提交于 2020-01-06 20:01:52
问题 I currently have a Client model that has_many pricings. Pricings table: create_table "pricings", force: true do |t| t.integer "product_id" t.integer "client_id" t.decimal "unit_price" t.datetime "created_at" t.datetime "updated_at" end Pricings model: class Pricing < ActiveRecord::Base belongs_to :client belongs_to :product validates :unit_price, presence: true end Client model: class Client < ActiveRecord::Base has_many :deliveries has_many :collections has_many :pricings accepts_nested

Deleting nested objects

跟風遠走 提交于 2020-01-06 14:01:17
问题 I have a profile, and this profile has many curso s (courses). I show all the courses a profile has on the show.html.erb of this profile. <% for curso in @profile.cursos %> <li><%=h curso.nome %> - <%=h curso.universidade %><br> Ingresso em: <%=h curso.ano_ingresso %> - Encerra em: <%=h curso.ano_termino %> <li> <%= button_to 'Delete', { :action => "destroy", :id => curso.id },:confirm => "Are you sure?", :method => :delete %> This way, I'm able to show all the courses a profile has on it's

Nested model form not working properly - need to pinpoint POST/GET redirect

此生再无相见时 提交于 2020-01-06 08:37:05
问题 I have a nested model form that isn't functioning properly. The POST is to the proper place, but then the GET reroutes me. So I'm wondering if anyone can help explain what I'm doing wrong. I have two models: User and Profile . Code for them below: User: class User < ActiveRecord::Base attr_accessor :password, :email has_one :profile, :dependent => :destroy accepts_nested_attributes_for :profile ... end Profile: class Profile < ActiveRecord::Base attr_accessible :first_name, :last_name, etc.

how can i implement parent-child relationship in rails3

非 Y 不嫁゛ 提交于 2020-01-06 07:11:43
问题 I'm creating a billing application in rails3, I have a confusion when it comes to creating a bill. one bill can have one or more items 'bill' has many 'items' 'item' belongs to 'bill' my requirement is as follows I should be able to create a new bill and add items to it (any number of items can be added) my problem is 1 - to get items to be saved in the bill_details table I should first generate bill_id, What is the best way to generate this bill id. 2 - what is the best way to implement a

how can i implement parent-child relationship in rails3

点点圈 提交于 2020-01-06 07:11:07
问题 I'm creating a billing application in rails3, I have a confusion when it comes to creating a bill. one bill can have one or more items 'bill' has many 'items' 'item' belongs to 'bill' my requirement is as follows I should be able to create a new bill and add items to it (any number of items can be added) my problem is 1 - to get items to be saved in the bill_details table I should first generate bill_id, What is the best way to generate this bill id. 2 - what is the best way to implement a

Ruby on Rails nested attributes not saving into database?

末鹿安然 提交于 2020-01-06 02:54:08
问题 I'm trying to create a list of items within a "Todo list", however, I'm not sure if I'm doing this correctly with nested attributes. I think using a nested attribute is the right attempt because there's going to be a large list of items, and it will be associated with the correct "Todo list" based on ids. Example of what the tables might look like when records are populated Todo table id list 1 grocery shopping 2 health insurance Item table id todo_id name 1 1 buy milk 2 1 buy cereal 3 2 Blue

How to access virtual attributes of model in a nested form with Rails

老子叫甜甜 提交于 2020-01-05 08:10:19
问题 I have a basic nested form. I want to access a virtual attribute for the nested form's model. Model 1: Lease Has_many :transactions accepts_nested_attributes_for :transactions, :reject_if => lambda { |a| a[:dated].blank? }, :allow_destroy => true ... Model 2: Transaction belongs_to :lease def balance_to_date(aDate) #Returns the current balance up to aDate ... end ... In the nested form I want to put something like: <td style="width:100px;"><%= nested_f.text_field :dated, size: 8 %> </td> <td

Doctrine2 inverse persistance not working in nested forms

瘦欲@ 提交于 2020-01-04 09:18:15
问题 I am creating a MotorsAds entity to which I am linking with MotorsAdsFile entity. For each MotorsAds , we could attach many MotorsAdsFile . My objective is creating a form for MotorsAds which allows adding MotorsAdsFile just through a click on a button. Here, I am trying to implement the embeded forms. My problem is that I got that error: An exception occurred while executing 'INSERT INTO MotorsAdsFile (filename, motors_id) VALUES (?, ?)' with params ["5493b613839d7_2012-07-02 22.06.00.jpg",

How to show nested form validation errors after the validation errors for the parent model?

戏子无情 提交于 2020-01-04 04:46:28
问题 Using Ruby on Rails 4.2, I have a nested form. When testing the validations for the entire form, I noticed that the validation errors for the nested form appear at the top of the validation errors list, with the validation errors for the main form appearing below. This is the opposite order that they are declared (since the fields_for has to appear within the scope of the parent form_for ), so it looks like this: [name ] [description ] [others ] [nested #1 ] [nested #2 ] But the validation