Tag: formtastic

Client_side_validations gem与jquery模态视图中的formtastic不起作用

我正在尝试获取client_side_validations gem以在jquery模式视图中validation我的表单,但validation没有发生(至少在错误未显示为内联的情况下)。 我也使用了formtastic gem,所以我已经安装了client_side_validations和client_side_validations-formtastic gems来进行formtastic支持。 注意:我在app / views / layouts / application.html.erb中包含rails.validations javascript 这是我的代码: 应用程序/视图/家/ index.html.erb: $(document).on(“click”, “btn-signup”, function trans() { Modal.prototype.hideWithTransition = function(){ $(“#signup”).fadeIn(); }; }); $(‘#new_user’).enableClientSideValidations(); $(‘#new_user’).on(‘shown’, function() { $(ClientSideValidations.selectors.forms).validate(); }); true, :validate => true do |f| %> × Test header Submit Sign up $(“#new_user”).on(“submit”, function hide_form() { $(“#signup”).modal(‘hide’); }); 应用程序/模型/ user.erb: class […]

Ruby on Rails + Formtastic:不检查多个已检查答案的复选框

编辑:底部的解决方案和选定的答案。 我一直在与Formtastic合作一段时间,而且大部分都是如何简化表单创建。 不幸的是,我遇到了使用复选框的问题。 保存/提交表单后出于某种原因,复选框未被检查。 代码片段 = ff.input :answer, :as => :check_boxes, :collection => ff.object.survey_question.options, :label => ff.object.survey_question.question – .options收集方法如下所示: def options opts = {} survey_options.each do |option| opts[option.option] = option.id.to_s end opts end 服从 表单返回以下(截断的)参数: params [:response] [:question_responses_attributes] = { “0”=> {“answer”=>”42”, “id”=>”1175”}, …, “3”=> {“answer”=>[“”, “52”, “54”, “56”], “id”=>”1178”}, … } 其中写入数据库为 — – […]

formtastic check_boxes使用集合而不是以编辑forms保存选中的项目

我知道这应该在Formtastic 2.0中修复,但由于某种原因,这对我不起作用。 :check_boxes, :collection => [“Male”, “Female”, “Unisex”] %> 每当我回去检查它时,项目总是再次被取消选中。 它从未显示为已选中。 我知道Justin French 在这里对此进行了评论,但我不确定这意味着什么或者如何帮我解决问题。 我将性别作为字符串保存在用户模型中,如果它有所不同。 我也在使用formtastic-bootstrap 1.1.1 谢谢!

Formtastic / rails表格未提交

我正在尝试使用formtastic制作一个表格,我可以进入:反对选择a:场地和a:团队然后会出现一个我可以检查选择它们的球员列表 我已经设置了表单以便正确呈现,但是在提交时它不会保存任何信息并只是重新加载页面。 我的代码在我的github: https : //github.com/jpknegtel/st_francis 楷模 这涉及以下模型: 播放机 has_many :player_fixtures has_many :fixtures, :through => :player_fixtures 灯具 has_many :player_fixtures has_many :players, :through => :player_fixtures PlayerFixture belongs_to :player belongs_to :fixture 调节器 def create @fixture = Fixture.new(params[:fixture]) if @fixture.save flash[:notice] = “Fixture Created” redirect_to(:action =>’list’) else flash.now[:error] = “Could not save fixture. Please re-enter information” render(‘new’) end […]

rails formtastic嵌套表单警告:无法批量分配受保护的属性

我跟随模特: class CapstoneMilestone false accepts_nested_attributes_for :milestone, :allow_destroy => false end class Milestone :capstone_milestones attr_accessible :id, :name, :description, :department_id, :project accepts_nested_attributes_for :capstone_milestones, :allow_destroy => true end 我也有一个formtasticforms: :select, :collection => Capstone.all %> :select, :collection => Milestone.all %> :numeric%> :numeric%> :numeric%> :numeric%> :milestone%> 我的capstone_milestone控制器(应该)负责更新: def update @milestone=@capstone_milestone.milestone # I also removed these 2 lines without success @milestone.update_attributes(params[:milestone_id]) […]

rails 3,paperclip(&formtastic) – 删除图像附件

我似乎无法找到所有组件中完整的示例。 我很难删除图片附件 类 class Product has_many :product_images, :dependent => :destroy accepts_nested_attributes_for :product_images end class ProductImage belongs_to :product has_attached_file :image #(etc) end 视图 {:multipart => true} do |f| %> :boolean, :label => image_tag(product_image.object.image.url(:thumb)) %> :file, :name => “Add Image” %> 调节器 class Admin::ProductsController ‘edit’ end end end 看起来不错,但是,当我选中复选框时,字面上没有任何反应。 在请求中我看到: “product”=>{“manufacturer_id”=>”2”, “size”=>””, “cost”=>”5995.0”, “product_images_attributes”=>{“0″=>{“id”=>”2”, “_destroy”=>”1”}} 但没有任何更新,产品图像也不会保存。 我错过了关于’accepts_nested_attributes_for’如何工作的基本信息吗?

formtastic中date_helper的默认值

听起来很基本,我不能将date_helper默认为日期,如: – semantic_form_for resource do |f| – f.inputs do = f.input :issued_on, :default => Date.today = f.buttons 如果资源没有日期,上面只会呈现空白列。 希望任何关于我可能做错的指针。

使用关联(has_many)模型中的字段和rails中的formtastic

我搜索并尝试了很多,但我无法按照我的意愿完成它。所以这是我的问题。 class Moving :destroy has_many :resources, :through => :movingresources end class Movingresource < ActiveRecord::Base belongs_to :moving belongs_to :resource end class Resource :movingresources end Movingresources包含其他字段,如quantity 。 我们正在研究“账单”的观点。 感谢formtastic通过写作简化整个关系的事情 :check_boxes %> 我得到一个真正漂亮的复选框列表。 但到目前为止我还没有发现的是:我如何使用’movingresource’中的附加字段,在每个复选框的下方或下方,从该模型中获取所需的字段? 我看到了不同的方法,主要是手动循环遍历一组对象并创建适当的表单,使用:for in form.inputs part,or。 但是这些解决方案都不是干净的(例如,为编辑视图工作但不适用于新的,因为没有构建或生成所需的对象并且生成它们导致混乱)。 我想知道你的解决方案!

通过Active Admin使用HABTM或Has_many

我已经阅读了很多关于使用活动管理员与has_many通过关联的post,但我没有得到所需的结果。 基本上我有2个模型“会议”和“帐户”。 我需要为会议分配多个帐户,为帐户分配多个会议。 我使用HABTM或has_many对我来说无关紧要。 我只需要在创建新会议时能够看到下拉选择选项,反之亦然。 帐户模型 class Account :destroy has_many :conferences, :through => :conferenceaccount end 会议模式 class Conference :conferenceaccount end 会议账户模型 class Conferenceaccount < ActiveRecord::Base belongs_to :conference belongs_to :account attr_accessible :account_id, :conference_id end 会议管理模型 ActiveAdmin.register Conference do form do |f| f.inputs “Details” do # Project’s fields f.input :conferencename f.input :address f.input :city f.input :state f.input […]

具有小数精度的Formtastic数字字段?

当然我错过了一些非常明显的东西……我有一个十进制精度为2的字段,但Formtastic只显示一个小数,除非实际值有2个位置。 我错过了什么? 模型: create_table “items”, :force => true do |t| t.string “item_number” t.integer “buyer_id” t.integer “seller_id” t.string “description” t.decimal “sales_price”, :precision => 10, :scale => 2, :default => 0.0 t.datetime “created_at” t.datetime “updated_at” end 视图 %td= bought.input :sales_price, input_html: { class: ‘span2’}, label: false 注意到下面的回答,其他人在以后发现这个问题可能并不清楚: %td= bought.input :sales_price, input_html: { class: ‘span2’, value: number_with_precision(bought.object.sales_price, precision: […]