Tag: 嵌套表单

如何在新操作中使用与belongs_to关联的嵌套属性?

在update操作上,以下nested_form可以正常工作,但在create我收到此错误: Couldn’t find Student with ID=12 for Cv with ID= 控制器: def new @cv = Cv.new @cv.student = current_student end def create @cv = Cv.new(params[:cv]) if @cv.save redirect_to student_dashboard_path, notice: t(‘activerecord.successful.messages.created’, model: @cv.class.model_name.human) else render ‘new’ end end 模型: class Cv < ActiveRecord::Base attr_accessible :student_attributes belongs_to :student accepts_nested_attributes_for :student end 视图: = f.simple_fields_for :student do […]

Rails – Cocoon gem – 嵌套表格

我正在尝试用Rails 4创建一个应用程序。 我为表单使用简单的表单gem,并尝试使用Cocoon gem作为表单的嵌套元素。 我问了这个问题,它解释了我想要更详细地实现的内容: Rails – 单个属性的多个条目 我有个人资料模型和资格模型。 协会是: profile.rb has_many :qualifications accepts_nested_attributes_for :qualifications, reject_if: :all_blank, allow_destroy: true qualification.rb belongs_to :profile 配置文件控制器包含强参数中的限定属性: def profile_params params[:profile].permit(:user_id, :title, :hero, :overview, :research_interest, :occupation, :external_profile, :working_languages, :tag_list, qualifications_attributes: [:id, :level, :title, :year_earned, :institution, :_destroy] ) end 我的个人资料表现在有: Your qualifications 我的资格部分表单现在在我的资格视图文件夹中命名为_qualifications_fields.html.erb “Your award” %> “When did you graduate?”, collection: […]

Rails 4嵌套表单 – 没有将Symbol隐式转换为Integer

在我的rails 4 app中,我有一个三重嵌套路线: devise_for :users do resources :foo do resources :marflar end end 我有一个用于创建带有嵌入式Marflar对象的新Foo的表单: 但是当我提交表格时,我得到: TypeError in FoosController#create no implicit conversion of Symbol into Integer 我的Foo控制器的相关部分如下所示: def new @foo = current_user.foos.build @foo.marflars.build end def create @foo = Foo.new(foo_params) if @foo.save redirect_to @foo else render action: ‘new’ end end .. def foo_params params.require(:foo).permit(:foo_attr, marflars_attributes: [:marflar_attr]) end […]

无法使用has_one关联获得嵌套表单

我有这些模型: class User < ActiveRecord::Base has_one :city accepts_nested_attributes_for :city end class City < ActiveRecord::Base belongs_to :user end 这个控制器动作: def create @user = User.new(params[:user]) respond_to do |format| if @user.save format.html { redirect_to(@user, :notice => ‘User was successfully created.’) } format.xml { render :xml => @user, :status => :created, :location => @user } else format.html { render […]

具有多态模型的嵌套forms

我正在创建一个具有以下属性的应用程序,我正在创建一个单独的表单,以便能够保存目标,目标的任务,目标的里程碑和里程碑的任务。 #app/models/goal.rb has_many :tasks, :as => :achievement has_many :milestones accepts_nested_attributes_for :tasks accepts_nested_attributes_for :milestones #app/models/milestone.rb belongs_to :goal has_many :tasks, :as => :achievement #app/models/task.rb belongs_to :achievement, :polymorphic => true 每当我用它的属性保存目标时,似乎任务模型对它们所属的成就类型感到困惑,导致每个里程碑任务被列为目标任务。 我的表单,部分和控制器代码如下。 形成: f.object %> f %> ff %> ff %> milestone_fields partial: ff %> task_fields partial: 目标控制器: def new @goal = current_user.goals.new end def create @user = […]

rails simple_nested_form_for fields_for错误的参数数量

所以我正在使用rails 3.1构建一个表单 collection_url, :html=>{:multipart => true}) do |f| %> “form”, :locals => { :f => f } %> 但部分中的这一行导致了问题: Badges // this following line is raising the error “wrong number of arguments (4 for 3)” ‘certification’, :locals => { :f => certification_form } %> 所以这是模型: class Person :destroy, :order=>:position has_many :certificates, :through=>:certifications accepts_nested_attributes_for :certifications, :allow_destroy […]

Rails 4:使用回形针上传多个图像

我希望将多个图像上传到我的“位置”模型。 我把图像称为“资产”。 一个位置有多个资产。 我也使用paperclip来处理上传和nested_form以允许选择多个资产。 奇怪的是,位置哈希看起来正确地传递变量,但它们似乎没有被资产模型拾取。 任何帮助都会很棒! 位置模型 class Location :location_post has_many :assets, dependent: :destroy attr_accessor :asset, :assets_attributes accepts_nested_attributes_for :assets, :allow_destroy => true end 资产模型 class Asset { :blurred => “600×300^”,:large => “600×600>”, :medium => “250×250^” , :thumb => “100×100^”}, #:source_file_options => {:all => ‘-rotate “-90>”‘}, :convert_options => { :all => ‘-auto-orient’, :blurred => “-blur 0x6 […]

多级嵌套表单未在Active Admin中显示

我正在尝试实现一个多级嵌套表单。 这些是我的模特 workout.rb has_many :workout_weeks accepts_nested_attributes_for :workout_weeks workout_week.rb belongs_to :workout has_many :workout_days accepts_nested_attributes_for :workout_days workout_day.rb belongs_to :workout_week 和我的锻炼编辑部分在活动管理员就像 form do |f| inputs ‘Workout Details’ do f.input :workout_name f.inputs do f.has_many :workout_weeks, heading: ‘Workout Week’, allow_destroy: true do |ww| ww.input :week_workout_name ww.inputs do ww.has_many :workout_days, heading: ‘Workout Days’, allow_destroy: true do |wd| wd.input :day_workout_name end end […]

使用nested_form获取对象值

我有一个嵌套的表单(订单中的付款),我想在编辑视图中测试我的嵌套表单(fields_for)中的值。 但问题是我无法检查每个,我可以这样做: 你现在是如何检查每个,如:

在Rails中将多级嵌套表单标记为“脏”

我在Rails中有一个三级多嵌套表单。 设置如下:项目有许多里程碑,里程碑有很多笔记。 目标是使用JavaScript在页面中编辑所有内容,我们可以在页面中向项目添加多个新里程碑,并将新Notes添加到新的和现有的里程碑。 一切都按预期工作,除了当我向现有的里程碑添加新笔记(新的里程碑在向他们添加笔记时工作正常)时,新笔记将不会保存,除非我编辑任何实际属于里程碑的字段以标记forms“脏”/编辑。 有没有办法标记里程碑,以便添加的新Notes将保存? 编辑:对不起,很难粘贴所有代码,因为有很多部分,但是这里有: 楷模 class Project :destroy has_many :milestones, :dependent => :destroy accepts_nested_attributes_for :milestones, :allow_destroy => true accepts_nested_attributes_for :notes, :allow_destroy => true, :reject_if => proc { |attributes| attributes[‘content’].blank? } end class Milestone :destroy accepts_nested_attributes_for :notes, :allow_destroy => true, :allow_destroy => true, :reject_if => proc { |attributes| attributes[‘content’].blank? } end class Note < […]