Tag: 嵌套表单

使用selectbox nested_form gem编辑模型

我有一个嵌套的表单gem问题,几天都无法搞清楚。 当“编辑”模型时,为什么我的选择框没有从数据库中填充当前值? 我的“自定义”视图: create_customize_cart_path do |f| %> # some field here builder %> 我的局部视图(嵌套): ‘– Select Position –‘} %> PRESSED POSITION为CONSTANT ,数据存储“字符串”值 PRESSED_POSITION = [ [“Top”, “top”], [“Center”,”center”], [“Bottom”,”bottom”], [“Right”, “right”], [“Left”, “left”], [“Top Left”, “top left”], [“Top Center”, “top center”], [“Top Right”, “top right”], [“Center Left”, “center left”], [“Center Center”, “center center”], [“Center Right”, […]

多模型嵌套表单,无法将用户添加到当前帐户

我到处寻找解决方案,但没有提出任何解决方案。 有效的部分 :我的应用程序允许客户使用嵌套表单创建帐户。 收集的数据在四个模型中创建记录 – 帐户,用户,accounts_users(因为用户可以与许多帐户关联)和配置文件(用于存储用户的fname,lname,phone等)。 该部分不起作用 :登录后,我希望用户能够使用下面的表单向其帐户添加更多用户。 我在提交时没有收到任何错误,但我被带回到同一表格,没有创建额外的记录。 任何帮助都是极好的! 这是嵌套表格…… true do |f| %> “btn btn-large btn-success” %> ApplicationController将所有内容范围限定为current_account,如下所示: def current_account @current_account ||= Account.find_by_subdomain(request.subdomain) if request.subdomain end UsersController def new @user = User.new @user.build_profile() #current_account.accounts_users.build() #Edit2: This line was removed respond_to do |format| format.html # new.html.erb format.json { render json: @user } end def […]

嵌套表单显示错误

我有一个新幼儿园的以下表格声明 {:multipart => true} do |f|%> 这背后的逻辑是1个幼儿园可以有多张照片。 以下是模型声明: 幼儿园 has_many :photos, limit: 7, dependent: :destroy accepts_nested_attributes_for :photos 照片 attr_accessible :image, :logo, :kindergarten_id belongs_to :kindergarten mount_uploader :image, ImageUploader validates :kindergarten_id, presence: true validates :image, presence: true 以下是幼儿园控制器的样子: def new @kindergarten = Kindergarten.new @kindergarden.photos.build end 现在,当@kindergarten new生成时,我收到以下错误: undefined method ‘photos’ for nil:NilClass Application Trace | Framework Trace […]

nested_form没有保存到模型Rails 3

虽然我无法将表单数据保存到模型中,但我认为我正处于以下方面。 我有2个型号 class Prediction < ActiveRecord::Base attr_accessible :home_team, :away_team, :home_score, :away_score, :fixtures_attributes has_many :fixtures accepts_nested_attributes_for :fixtures end class Fixture < ActiveRecord::Base attr_accessible :home_team, :away_team, :fixture_date, :kickoff_time belongs_to :predictions end 为了创建一个新的预测记录,我有一个表单可以获取所有的灯具并预先填充表单,用户只需在每个团队旁边添加分数 <%= f.fields_for :fixtures, @fixtures do |ff| %> VS 然后我让我的控制器来处理新的/创建动作,我认为这是我可能会摔倒的地方 class PredictionsController ‘Predictions Submitted Successfully’ else render ‘new’ end end end 最后我的路线 resources :predictions resources :fixtures […]

fields_for for nested属性不返回任何内容

我正在尝试在Rails 3.0.3中创建一个嵌套的模型表单。 这是我的模特: class Bird :organism accepts_nested_attributes_for :taxon end class Taxon true end 这是控制器方法: def new @bird = Bird.new @bird.build_taxon end 以下是表格: New Bird 当我运行新方法时,分类的字段不会显示。 html源代码中没有任何暗示。 我听说如果嵌套模型为零(即如果我忘记在控制器方法中构建它),就会发生这种情况,但它就在那里。 我在视图中添加了一些条件代码以确保。 那么,谁会让我在这里砸我的额头? 我错过了什么? 谢谢!

嵌套表单复杂has_many:通过

我有一个复杂的has_many通过关系,用户可以通过应用程序申请工作。 在创建每个作业时,管理员会选择某些问题。 在Applications#new期间,当用户申请新工作时,我也希望用户回答问题以便申请。 为此,我设置了我的模型: Job has many users through application has many questions Users has_many jobs through application Application belongs_to :user belongs_to :job has_many :answers Question belongs_to :job has_one :answer Answer belongs_to :application belongs_to :question 我现在有一个应用程序控制器。 这就是我被困的地方。 如何让用户能够回答有关Applications#new view的问题? 这就是它到目前为止的样子 – > 应用控制器 class ApplicationsController “Something went wrong. Please contact us and mention this” end […]

如何在Rails 3中通过嵌套表单传递外键属性

我有三个型号: class Client :balancesheets class Balancesheet :destroy accepts_nested_attributes_for :investment_assets, :allow_destroy => true class InvestmentAsset < ActiveRecord::Base belongs_to :balancesheet belongs_to :client 我有两个与外键client_id有关的问题。 首先,当我创建新的余额表时,我使用collection_select从列表中选择客户端。 我宁愿将新的资产负债表链接放在客户端显示页面上,只是将客户端ID传递给表单,这样我就不必从列表中选择客户端或在字段中键入它。 首先,我该怎么做? 其次,investment_asset模型嵌套在balancesheet表单中。 除了investment_asset的client_id属性为空之外,一切正常。 我不知道为什么,因为我的协会似乎没问题。 所以问题是,如何通过嵌套表单传递此client_id属性? 我可以发布模型或控制器,只是让我知道。 更新我已经在这里找到了我的第一个问题的答案。 但是,我仍然试图找出基于该答案的第二部分,即如何通过嵌套表单传递此client_id? 要显示在创建资产负债表时如何通过用户ID,这里是客户端显示页面链接: @client.id) %> 在资产数据表中,我有一个隐藏的字段: 在资产负债表控制器中,这是新的操作: @balancesheet = Balancesheet.new(:client_id => params[:id]) 这很好用。 所以对于investment_asset,我使用的是Ryan Bates nested_form gem ,它对链接有一些不同的语法。 因此,在资产数据表中,添加新的investment_asset的链接是: 我无法弄清楚如何传递用户ID,就像我在资产负债表上所做的那样: (:id => @client.id) 我可以在invest_asset控制器中的新操作中添加相同的内容并添加隐藏字段,但我不确定如何在链接上传递它。 思考?

包含嵌套表单的深层嵌套表单

我看到使用深度嵌套表单的railscast进行调查: http://railscasts.com/episodes/196-nested-model-form-revised?view=asciicast 你如何在Rails中构建类似于实际/采取/调查的东西,而不是仅构造它以在文本中显示? 你如何制作一个包含用户填写的调查表格的深层嵌套表格?

Rails:无法找到带ID的嵌套资源

我有一个3层嵌套模型:画廊 – >有很多专辑 – >有很多照片 当我尝试从这里添加一个新专辑时http:// localhost:3000 / galleries / 1 / albums / new我得到了 “AlbumsController中的ActiveRecord :: RecordNotFound #create无法找到带有’id’=”的图库 专辑型号: class Album < ApplicationRecord belongs_to :gallery has_many :photos accepts_nested_attributes_for :photos 画廊模型 class Gallery < ApplicationRecord has_many :albums accepts_nested_attributes_for :albums end 路线 …. resources :galleries do resources :albums end resources :photos, only: [:index, :new, :create, :destroy] […]

Rails嵌套表单不更新

我在获取update_attributes以更新表单中的嵌套模型时遇到问题。 我没有任何错误,但嵌套属性不保存。 这是相关的代码: 用户型号: class User < ActiveRecord::Base has_many :orders has_many :achievements accepts_nested_attributes_for :achievements 成就模型: class Achievement < ActiveRecord::Base belongs_to :user 编辑用户表单: { :multipart => true } do |f| %> … 编辑方法: def edit @user = nil if params[:id] != nil @user = User.find(params[:id]) elsif @user = current_user else redirect_to login_path end 5.times { @user.achievements.build […]