nested-attributes

Nested simple_form with polymorphic association. Unpermited parameter

自作多情 提交于 2019-12-12 06:01:57
问题 It's a lot of question about it all around, but I can't find the answer. I've: group.rb class Group < ActiveRecord::Base has_many :descriptions, :as => :describable accepts_nested_attributes_for :descriptions end description.rb class Description < ActiveRecord::Base belongs_to :describable, :polymorphic => true end groups_controller.rb def update @group = Group.find(params[:id]) if @group.update_attributes(group_params) flash[:success] = "yes" redirect_to groups_path else render 'edit' end

Nested attributes are not updating in rails

て烟熏妆下的殇ゞ 提交于 2019-12-12 05:15:09
问题 I have 3 models: class DropShipOrderLineItem < ActiveRecord::Base belongs_to :drop_ship_order belongs_to :line_item validates_associated :drop_ship_order validates_associated :line_item validates :drop_ship_order_id, :presence => true validates :line_item_id, :presence => true attr_accessible :missing end class DropShipOrder < ActiveRecord::Base attr_accessible :line_items, :line_items_attributes, :orders, :order_attributes belongs_to :retailer belongs_to :order belongs_to :shipping_method

Rails: prevent submitting form if field is blank

点点圈 提交于 2019-12-12 03:49:08
问题 I am creating product page, where user can upload more than one photo of product. To create and edit product, i am rendering a form file. For uploading photos, i have used nested_fields for photos in the form of the product. Here is how photo code in the form looks like: <%= f.fields_for :photos do |photo| %> <%= image_tag photo.object.avatar.url(:thumb), unless f.object.new_record? or photo.object.new_record? %> <%= photo.file_field :avatar, :style => "none" %> <%= photo.link_to_remove

Rails nested Attributes of join table won't be saved

限于喜欢 提交于 2019-12-12 01:35:58
问题 Nested attributes of join model won't be saved. relation id's seems to be missing. The following error messages are added when the fields get validated: * Assigned projects user can't be blank * Assigned projects project can't be blank The submitted params look like this ( <%= debug(params) %> ) --- !map:ActionController::Parameters utf8: "\xE2\x9C\x93" authenticity_token: HrF1NHrKNTdMMFwOvbYFjhJE1ltlKbuz2nsfBYYBswg= project: !map:ActionController::Parameters name: Peter Pan assigned_projects

How to make text fields for nested_attributes in rails for selected records?

我与影子孤独终老i 提交于 2019-12-12 00:34:44
问题 I have a three models Report , Question , Answer Answer belong_to :question Question belong_to :reports has_many :answers, :dependent => :destroy accepts_nested_attributes_for :answers, :allow_destroy => true Reports has_many :questions, :dependent => :destroy accepts_nested_attributes_for :questions, :allow_destroy => true While creating a new report some questions are randomly picked to be added to the report and show form in this way : Report Form <%= form_for @report do |f| %> <div class=

Rails 3 — Build not saving to database (Railscast 196)

为君一笑 提交于 2019-12-11 23:25:51
问题 I'm following along with railscast 196. I've got two levels of associations. App -> Form -> Question. This is the new action in the form controller. def new @app = App.find(params[:app_id]) @form = Form.new 3.times {@form.questions.build } end the view is displaying all 3 questions fine and I can submit the form... but nothing is inserted into the database for the questions. Here is my create action def create @app = App.find(params[:app_id]) @form = @app.forms.create(params[:form]) respond

Is there a better way to name this field appropriately?

痞子三分冷 提交于 2019-12-11 23:15:38
问题 I have the following form code (irrelevant parts omitted): <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { id: "payment-form" }) do |f| %> <%= f.fields_for resource.paid_account do |pa| %> <%= pa.collection_select :account_plan_id, @account_plans, :id, :name_with_price, {}, { name: "user[paid_account_attributes][account_plan_id]" } %> <% end %> <% end %> You can see the dumb part on the 4th line: I'm hard-coding the name to user[paid_account_attributes

Edit Form Delete's a record from the database

…衆ロ難τιáo~ 提交于 2019-12-11 22:59:55
问题 I Have a nested form that works pretty well in saving content to the database. The only problem is that when I click edit, the "grand-child" field is deleted from the database and thus I have to re-enter everything on that field. The normal behavior is on editing the previous content should be present. I am using gem cocoon for nested forms simple_forms for my forms and ckeditor for richtext editing. This is the server log when I click edit: notice: SQL (0.3ms) DELETE FROM "responses" WHERE

ActiveRecord::AssociationTypeMismatch when trying to register user using devise

扶醉桌前 提交于 2019-12-11 18:22:37
问题 I am trying to attach nested fields in register process with devise gem. I want to create video that belongs to User after User creation in one request. Form sends post to create method from registrations_controller.rb and it fails at sign_up params new.html.erb <%= form_for(resource, as: resource_name, url: registration_path(resource_name), remote: true) do |f| %> <input name="authenticity_token" type="hidden" value="<%= form_authenticity_token %>"/> <div data-behavior="devise-error-messages

Rails 4 nested attribute hash keys showing as unpermitted

隐身守侯 提交于 2019-12-11 13:42:34
问题 I have a Category model and a Standard model. A category has many standards through a "join table" model CategoryStandard . In my view, I have a form where I can edit the category description, and then add or remove standards from that category. So, my nested attributes are for :category_standards , because I'm not editing the standard itself, just adding or removing relationships, if that makes sense. Here's the important part of the view: <%= form_for(@category) do |f| %> ... <div class=