Tag: forms

如何在Ruby on Rails 3中以嵌套forms调用对象上的方法?

我有这两个型号 class Invoice < ActiveRecord::Base has_many :items accepts_nested_attributes_for :items … end class Item < ActiveRecord::Base belongs_to :invoice def total price * quantity end … end 这个嵌套(!)forms发布到两个模型: Add an Invoice Items 如何对表单中的项目进行计算? 在我的Items模型中,我有这个方法: def total price * quantity end 但是,在forms上我无法使用f.total 。 我一直收到这个错误: undefined method `total’ for # 我在这里想念的是什么?

以简单forms手动设置表单输入字段的ID?

是否有可能在表单中否决simpleform的文本字段命名? 这个: = f.input_field :age_from, 输出: 应该 我试过*:name =>“query”*:id =>“query” 无济于事

干掉一个帮手:包装form_for并访问本地表单变量

我试图干掉一堆表单代码,这些表单代码在每个表单的末尾出现一组重复的字段。 我写了一个包装form_for rails helper的帮助器。 但是我开始迷失在飞来飞去的所有不同范围…… 我的助手是这样的: def simple_form_helper(record_or_name_or_array, *args, &proc) options = … # overriding some options, not relevant form_for(record_or_name_or_array, *(args < “blah”)) , &proc) # i wish to access &proc and append the call to render # to within &procs scope (to access block local variable) concat render(‘shared/forms/submit’) # this obv does not work […]

除非我刷新页面form_for Rails,否则提交按钮不起作用

我有一个有问题模型的应用程序,当我去创建一个记录时,提交按钮什么都不做。 除非我刷新页面并尝试再次添加它,否则没有错误只是根本不执行。 当我更新记录时也会发生同样的情况。 这是我的控制器 class ProblemsController < ApplicationController include Concerns::Votes def index @problems = Problem.all end def show @problem = find_problem end def new @problem = Problem.new end def edit @problem = find_problem end def create @problem = current_user.problems.new(problem_params) @problem.save redirect_to @problem end def update @problem = find_problem if @problem.update_attributes(problem_params) redirect_to @problem else redirect_to @problem […]

在Rails中关联标签和单选按钮

我正在使用Rails 2.3.8。 我的代码: 输出: Draft Published 显然label没有正确地与我的单选按钮相关联。 我想使label与单选按钮id相同。 我该如何纠正? 谢谢。

Form_for with:multipart => true吐出

我正在尝试将“头像上传”字段添加到我的个人资料页面,但是只要我添加:html => {:multipart => true} ,就会出现语法错误。 { :multipart => true } do |f| %> 错误是: syntax error, unexpected tASSOC, expecting keyword_end …end= form_for(@user), :html => { :multipart => true } do |f… … ^

Rails:多次使用form_for(DOM ID)

我想在同一页面中为同一个模型多次使用form_for帮助器。 但是输入字段使用相同的ID属性(在HTML中),因此单击另一个表单中字段的标签将在第一个表单中选择相同的输入。 是否有解决方案除了通过以下方式手动设置所有属性:for =>“title _#{item.id}”和:id =>“title _#{item.id}”? 使用Rails 3.0.9

在Rails 3中联系我们表格

我只想在我的Rails应用程序中使用姓名,电子邮件和消息字段联系我们表单,我不想保存(永久)消息我只想将消息作为我的电子邮件帐户的电子邮件发送。 你能帮助我吗? 谢谢!

从外部表格接收POST

我在另一个网站(使用不同的后端)上有一个表单,我希望能够POST到我的Rails应用程序(在不同的域上)。 如何为外部表单生成有效的真实性令牌,以便我的Rails应用程序可以接受它? 假设我可以回答上面的问题 – 我还需要做些什么特别的工作来完成这项工作吗? 除了真实性令牌,其余部分对我来说似乎很简单…… 谢谢您的帮助!

Simple_form错误 – ActiveRecord :: Relation:Class的未定义方法`model_name’

我试图通过将params传递到where来为我的编辑操作添加一些条件逻辑。 每当我使用.find(params [:id]以外的任何东西时,ActiveRecord :: Relation:Class的错误未定义方法`model_name’ 我的代码如下 控制器: def edit @office = Office.where(“id = ? AND company_id = ?”, params[:id], @company.id ) end 视图: settings_office_path, :html => { :class => “office_form” } do |f| %> Edit Details ‘form’, :locals => { :f => f } %> 我输出了@office的类,它是ActiveRecord :: Relation。 如果我只是用 @office = Office.find(params[:id]) 输出是Office。 我认为这是问题,但不知道如何解决它。 有任何想法吗?