Tag: 字段

如何在rails 3中validation“file_fields”

我是rails的新手,请指导我。 我想validation“file_field”以进行图片上传。 只需jpg / png / gif即可上传,特定尺寸如最大尺寸(500×500) 这是我的_form.html.erb {:multipart => true} ) do |f| %> prohibited this photo from being saved: ‘115×20’ %> File 我试图像这样进行validation class Photo false, :with => %r{\.(gif|jpg|png)$}i, :message => ‘must be a URL for GIF, JPG ‘ + ‘or PNG image.’ end 而错误就是这样的 undefined method `upload’ for # 我错过了什么吗?

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源代码中没有任何暗示。 我听说如果嵌套模型为零(即如果我忘记在控制器方法中构建它),就会发生这种情况,但它就在那里。 我在视图中添加了一些条件代码以确保。 那么,谁会让我在这里砸我的额头? 我错过了什么? 谢谢!

当form_for使用符号时,fields_for不起作用

我有一个form_for代码 {:controller=>”biz/a”,:action=>”save”},:html =>{:multipart => true} do |f| %> ….. ….. … …. 它输出没有fields_for函数的html代码 当我将form_for更改为: {:controller=>”biz/a”,:action=>”save”},:html =>{:multipart => true} do |f| %> 它只是工作正常。 它输出: 我想要的。 为什么form_for中的符号不​​能正常工作?在form_for中a和@a之间有什么区别? 谢谢。 我使用rails 2.3.8,ruby 1.8.7,chrome web浏览器。

使用fields_for的Rails错误消息

在我的子分类帐会计应用程序应用程序中,我有一个基金模型 class Fund < ActiveRecord::Base belongs_to :agency has_many :gl_accounts accepts_nested_attributes_for :gl_accounts attr_accessible :name, :agency_id, :fund, :user_stamp, :active attr_accessible :gl_accounts_attributes 和gl_accounts模型 class GlAccount true validates_uniqueness_of :account_type, :scope => :fund_id, :if => :unique_account_type attr_accessible :agency_id, :fund_id, :name, :gl_account_number, :active, :user_stamp, :account_type def unique_account_type [3,4,6,7,8].include? account_type end 当创建新基金时,必须同时创建5个gl_accounts,因此当为基金创建新记录时,我使用fields_for在gl_account模型中创建5个新记录。 这一切似乎都工作正常,直到我提交表格,我得到一个错误说“Gl账户基金不能空白。” gl_accounts模型中没有“fund”属性。 我认为也许rails正在放弃“_id”部分(因为有一个fund_id外键字段)但我理解使用嵌套模型和fields_for自动在fund_id字段中添加适当的值(gl_account的外键)模型)。 但即使我在表单中添加一个带有fund_id值的隐藏字段,我仍然会得到错误,说“基金”不能为空。 那么,也许rails试图告诉我我还有别的错吗? 以下是参数: {“utf8″=>”✓”, “authenticity_token”=>”MNWLFOnLOE+ZRsUf9mogf2cq/TeQ+mxtrdaVu3bEgpc=”, “fund”=>{“agency_id”=>”1”, “user_stamp”=>”6”, […]

多态嵌套表单对象创建的未知属性

我试图通过fields_for创建一个关联的多态对象。 我得到一个未知的属性错误,虽然父母被创建时,@ order参数是不是以某种方式通过? 家长/订单控制器 – # GET /orders/new def new @order = Order.new @order.build_patient @order.product = OrthosisSpecification.new end # GET /hotels/1/edit def edit @order.build_patient end # POST /orders # POST /orders.json def create @order = Order.new(order_params) respond_to do |format| if @order.save format.html { redirect_to @order, notice: ‘Order was successfully created.’ } format.json { render :show, […]

使用nested_form获取对象值

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

Fields_for动态标签

我有动态表单,它有一组值。 我创建了一个包含我显示的文本字段的部分。 在每个人旁边,我想显示一个包含文本标题的标签。 例如,先前不知道名字和姓氏。 我该怎么做呢? 似乎我无法直接访问属性。 但是当我使用标签字段时,标签中的变量名称不会显示实际值。

添加accepts_nested_attributes_for时,Fields_for消失

我在Rails 3.2.5中做了一个嵌套的表单,但是当我添加accepts_nested_attributes_for我的fields_for消失时(它们只是停止在我的表单中显示)。 这是我的模特: class Product < ActiveRecord::Base attr_accessible :title, :description, :variants_attributes has_many :variants accepts_nested_attributes_for :variants validates :title, presence: true end 我的第二个模特是 class Variant < ActiveRecord::Base belongs_to :product attr_accessible :price, :sku, :weight, :inventory_quantity, :product_id end 在我看来,我有 {:multipart => true} do |f| %> Producto Nuevo ** ** _inventory_fields.html.erb **之间的部分是未打印的部分。 当我在我的产品模型fields_中删除accepts_nested_attributes_for时,再次开始显示,但我的表单不起作用。 发生了什么?!?!

使用带有fields_for的数组

如何使用fields_for迭代一组对象(所有相同的模型)? 该数组包含current_user创建的对象。 我目前有: 3 %> current_user.id %> 但我想用我在控制器中创建的数组替换:descriptbyuser – @descriptionsFromCurrentUser 这也是Ryan Bate的“nested_form_for”内部 任何指针将不胜感激! 亚当

如何将数组传递给Rails中的fields_for?

我想在关联中的记录子集上使用fields_for 。 我有Month模型, has_many :payments 。 但在我看来,我只想在其中支付部分款项。 例如: – fields_for @month.payments.large 这不起作用。 我可以将一组记录传递给fields_for ,而不是通常的符号( fields_for :payments )方法吗?