fields-for

Plural for fields_for has_many association not showing in view

别等时光非礼了梦想. 提交于 2019-12-05 10:36:53
Currently, an Item belongs_to a Company and has_many ItemVariants . I'm trying to use nested fields_for to add ItemVariant fields through the Item form, however using :item_variants does not display the form. It is only displayed when I use the singular. I have check my associations and they seem to be correct, could it possibly have something to do with item being nested under Company, or am I missing something else? Thanks in advance. Note: Irrelevant code has been omitted from the snippets below. EDIT: Don't know if this is relevant, but I'm using CanCan for Authentication. routes.rb

Fields_for dynamic label

你。 提交于 2019-12-05 03:38:01
I have dynamic form which has a set of values. I created a partial which contains text fields which I display. Next to each of them I would like to display a label containing the title of the text. For instance First Name, and Last Name would not be known previously. How do I go about doing that? It seems that I cannot access the attributes directly. But when I use the label field, the variable name in the label is displayed not the actual value. sebajb Well! This was a reflection of how new I am to rails. You can do this by using f.object.{attr_name} and that worked. f.object.{attr_name} didn

Rails — fields_for not working?

社会主义新天地 提交于 2019-12-05 01:51:12
问题 When I run the rails server and go to the school/new page on my site, the field with the label "school" where I can enter the school's name appears, but all the other fields under fields_for which are for entering the school administrator's info do not show up on my site -- when I use "inspect element" on my form it is like they are not even there. Why aren't they appearing on my page? <%= form_for(@school) do |f| %> <% if @school.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(

Rails 3: nested_form, collection_select, accepts_nested_attributes_for and fields_for

旧时模样 提交于 2019-12-04 11:57:43
问题 Update: answered here. There are lots of good questions and answers here and on the interweb about getting nested_form, collection_select, accepts_nested_attributes_for and fields_for to play nicely together, but I'm still stumped. Thanks in advance if you can help me. Aim: To generate a new isbn record. An isbn can have many contributors. I am successfully using the ryanb nested_form gem to dynamically produce new contributor fields on a form, as required. One of these fields uses a

Rails 3 fields_for - sort order gets lost

怎甘沉沦 提交于 2019-12-04 09:06:56
问题 I am using Rails 3.0.3 with ruby 1.9.2p0. In my profiles_controller (edit function) I have this call @profile = Profile.find(params[:id]) @profile_items = @profile.profile_items.order("pos") to get the @profile_items in the correct order, sorted on "pos". In the _form.html.erb I have the following <% @profile_items.each do |pi| %> <%= pi.pos %> | <% end %> <%= f.fields_for :profile_items do |f2| %> <%= render 'profile_item_fields', :f => f2 %> <% end %> The 3 first lines are test code to show

Rails 4: fields_for in fields_for

╄→гoц情女王★ 提交于 2019-12-04 08:07:43
问题 I am learning RoR and i am trying to find how to set a fields_for in another one with has_one models like this: class Child < ActiveRecord::Base belongs_to :father accepts_nested_attributes_for :father end class Father < ActiveRecord::Base has_one :child belongs_to :grandfather accepts_nested_attributes_for :grandfather end class Grandfather < ActiveRecord::Base has_one :father end I used Nested Model Form Part 1 on Railscasts to get these: In children_controller.rb: def new @child = Child

fields_for in rails view

∥☆過路亽.° 提交于 2019-12-04 05:43:24
问题 When I attempt to use fields_for in the view code below, the company_name is not showing up in the view. What am I doing wrong? = form_for @company do |f| -if @company.errors.any? #error_explanation %h2= "#{pluralize(@company.errors.count, "error")} prohibited this company from being saved:" %ul - @company.errors.full_messages.each do |msg| %li= msg =f.fields_for :showing do |t| .field = t.label :company_name = t.text_field :company_name .field = f.label :geography = f.text_area :geography

using an array with fields_for

谁都会走 提交于 2019-12-03 07:56:23
问题 How can I iterate through an array of objects (all the same model) using fields_for ? The array contains objects created by the current_user. I currently have: <%= f.fields_for :descriptionsbyuser do |description_form| %> <p class="fields"> <%= description_form.text_area :entry, :rows => 3 %> <%= description_form.link_to_remove "Remove this description" %> <%= description_form.hidden_field :user_id, :value => current_user.id %> </p> <% end %> But I want to replace the :descriptionsbyuser with

Rails 3: nested_form, collection_select, accepts_nested_attributes_for and fields_for

五迷三道 提交于 2019-12-03 07:47:25
Update: answered here . There are lots of good questions and answers here and on the interweb about getting nested_form, collection_select, accepts_nested_attributes_for and fields_for to play nicely together, but I'm still stumped. Thanks in advance if you can help me. Aim: To generate a new isbn record. An isbn can have many contributors. I am successfully using the ryanb nested_form gem to dynamically produce new contributor fields on a form, as required. One of these fields uses a collection_select drop down of all the name records in Contributor. When the new record is created, the many

Rails 3 fields_for - sort order gets lost

社会主义新天地 提交于 2019-12-03 02:07:21
I am using Rails 3.0.3 with ruby 1.9.2p0. In my profiles_controller (edit function) I have this call @profile = Profile.find(params[:id]) @profile_items = @profile.profile_items.order("pos") to get the @profile_items in the correct order, sorted on "pos". In the _form.html.erb I have the following <% @profile_items.each do |pi| %> <%= pi.pos %> | <% end %> <%= f.fields_for :profile_items do |f2| %> <%= render 'profile_item_fields', :f => f2 %> <% end %> The 3 first lines are test code to show that the @profile_items are in the correct order. But when they are rendered they have lost the sorted