nested-forms

Get object value with nested_form

心不动则不痛 提交于 2019-12-07 07:20:49
问题 I have a nested form (payments in an order) and I would like to test a value in my nested forms (fields_for) in edit view. But the problem is that I am not able to check each, I can just do this: <% if @order.payments[0].monthly == false %> Do you now how it is possible to check for each, like: <% if @order.payments[current_payment].monthly == false %> 回答1: If I understand the question, you are editing an order and have a fields_for for the payments and want to get the payment instance

Marking multi-level nested forms as “dirty” in Rails

不羁的心 提交于 2019-12-07 06:05:35
问题 I have a three-level multi-nested form in Rails. The setup is like this: Projects have many Milestones, and Milestones have many Notes. The goal is to have everything editable within the page with JavaScript, where we can add multiple new Milestones to a Project within the page, and add new Notes to new and existing Milestones. Everything works as expected, except that when I add new notes to an existing Milestone (new Milestones work fine when adding notes to them), the new notes won't save

ASP .NET MVC 3 - How to submit an ajax form nested within an html form

≡放荡痞女 提交于 2019-12-06 23:18:57
问题 I have an ASP .NET MVC 3 project and a problem with one of my 'Create' views. I have cascading drop-down fields that I have implemented with ajax forms. The view is roughly speaking - like this: @using (Html.BeginForm(...)) { @Html.MyDropDown1 using (Ajax.BeginForm(...)) { @Ajax.MyDropdown2 <input type="submit" value="Select" /> } using (Ajax.BeginForm(...)) { @Ajax.MyDropdown3 <input type="submit" value="Select" /> } <!-- other form fields --> <input type="submit" value="Create" /> } The

Invalid association. Make sure that accepts_nested_attributes_for is used for :questions association

让人想犯罪 __ 提交于 2019-12-06 21:47:32
i am building nested form in rails 4.I keep getting this error my _form.html.erb as <%= nested_form_for (@project) do |f| %> <% if @project.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@project.errors.count, "error") %> prohibited this project from being saved:</h2> <ul> <% @project.errors.full_messages.each do |message| %> <li><%= message %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= f.label :name %><br> <%= f.text_field :name %> </div> <%= f.fields_for :questions do |builder| %> <%= render "question_fields", :f => builder %> <% end %> <div class="actions">

rspec doesn't see fields dynamically added or removed by cocoon in nested form

微笑、不失礼 提交于 2019-12-06 21:13:35
In my application in Rails 4, I use Cocoon to have nested forms. It works well in the browser, but I want to add some tests with rspec. If I make a click_link("add") (or 'remove') in my test, rspec doesn't see any modification (I print page.body before and after). I also tried with a sleep(10) but it's the same. How could I test if the action (add or remove a nested form) works well ? Thanks EDIT: The scenario to test : scenario "nested form" do user_sign_in contact = FactoryGirl.create(:contact) visit new_message_path expect(page).to have_text("New message") puts page.html click_link('Add an

Rails nested forms with pre-defined fields as checkboxes

大城市里の小女人 提交于 2019-12-06 12:27:29
问题 I'm making a hotel app that includes Room and RoomAttribute models. The two models have a many_to_many relationship between each other through a join table. The attributes for each model are as follows: Room – room_number , room_type (e.g. "deluxe" or "suite"), and price . RoomAttributes – name (e.g. "Wireless Internet", "Cable TV", "Bath Tub"). The user will first create a set of room attributes, so that these can be selected as checkboxes every time a new room is created. For example, some

Turning a calendar into a form using Rails?

江枫思渺然 提交于 2019-12-06 11:04:38
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://github.com/p8/table_builder (both gem and plugin do not deploy with rails 3.1) class WorkoutsController.rb

nested forms for 2 models in rails using dm-accepts_nested_attributes and dm-is-tree

≯℡__Kan透↙ 提交于 2019-12-06 08:39:48
I have two models: Post and Image in a forum application where Posts are arranged in parent-child format using dm-is-tree. Up this point, the images had been part of the Post model. As the Post model gets unwieldy and I need to add more depth to notating the image, I'm working to spin off the Image into its own model, but is still part of the post in output. So I started integrating dm-accepts_nested_attributes in a simple arrangement: class Post include DataMapper::Resource property :id, Serial property :istop, String property :created_at, DateTime property :updated_at, DateTime property

Correctly displaying nested models in my show view

元气小坏坏 提交于 2019-12-06 08:08:18
I'm new to rails and I'm slightly confused on how to properly display nested model attributes in a view. I'm using Rails 3.2.6. My 3 models here: class Company < ActiveRecord::Base attr_accessible :name, :vehicles_attributes, :engines_attributes has_many :vehicles, :dependent => :destroy accepts_nested_attributes_for :vehicles, :allow_destroy => true, :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } } end class Vehicle < ActiveRecord::Base attr_accessible :company_id, :engines_attributes belongs_to :company has_many :engines, :dependent => :destroy accepts_nested_attributes_for

Rails Nested Forms Not Updating Nested Model

这一生的挚爱 提交于 2019-12-06 07:07:17
I am having trouble trying to update nested models in my form. I don't get any errors and but the attributes don't get updated. I have the following model: class Trip < ActiveRecord::Base has_many :segments accepts_nested_attributes_for :segments, allow_destroy: true end class Segment < ActiveRecord::Base belongs_to :start_location, class_name: 'Location' belongs_to :end_location, class_name: 'Location' belongs_to :trip validates_presence_of :date, :start_location, :end_location end class Location < ActiveRecord::Base has_many :segments end And have this code in the _form.html.erb: <%= form