Tag: simple form

Rails + MongoID +简单forms关联:#Mongoid :: Relations :: Metadata的未定义方法`options’

我有以下模型,基本上是指课程和类别。 每节课可以有一个类别,每个类别都嵌入在课程中。 class Lesson include Mongoid::Document field :title, :type => String field :category, :type => String field :price, :type => Integer field :description, :type => String field :user_id, :type => String validates_presence_of :title validates_presence_of :category validates_presence_of :price validates_presence_of :user_id validates_numericality_of :price attr_accessible :title, :category, :description, :price embeds_one :category end class Category include Mongoid::Document field :name, […]

未定义的方法`simple_nested_form_for’

为什么我在尝试使用nested_form Rails插件时遇到此错误?

如何使用复选框应用带有acts_as_taggable_on的标签?

我想使用acts_as_taggable_on为公司模型分配两种不同的“类型”标签(扇区类别和免费标记)。 NB:我是RoR的新手! 如果只使用标准文本输入字段,这很容易做,但我想在一种类型(预定义的固定扇区类别标记)上使用复选框,然后允许用户在输入字段中添加逗号分隔标记。 我已经以各种方式解决了这个问题,……一个受这个问题启发的问题 ……但我无法让它发挥作用 这是我到目前为止: # models/company.rb class Company … acts_as_taggable_on :tags, :sectors has_many :taggings, :as => :taggable, :include => :tag, :class_name => “ActsAsTaggableOn::Tagging”, :conditions => { :taggable_type => “Company” } has_many :sector_tags, :through => :taggings, :source => :tag, :class_name => “ActsAsTaggableOn::Tag”, :conditions => {:context => “sectors”} end 在表单中(使用simple_form gem)我有…… # views/companies/_form.html.haml = simple_form_for […]

accept_nested_attributes_for:allow_destroy,:_ destroy无效

我有一个Rails 4.1应用程序,它使用了一些值得注意的技术。 简单的forms,茧 我无法销毁嵌套属性的记录。 基于一些冗长的研究,我相信我的代码是正确的,但我可能会遗漏一些愚蠢的东西。 模型 has_many :staff_services_joins, :dependent => :destroy has_many :services, :through => :staff_services_joins accepts_nested_attributes_for :staff_services_joins, :allow_destroy => true 这有点不正统,但我在连接模型上有两个组件,它们不是外键,需要设置。 这就是为什么我接受连接模型的嵌套属性而不是服务模型。 控制器方法 def update ap staff_params # if @staff_member.update_with_account staff_params, params[:password] if @staff_member.update_attributes staff_params flash[:notice] = ‘Successfully updated staff member! :)’ redirect_to vendor_store_staff_path current_store, @staff_member else flash[:error] = ‘Failed to update staff member […]

has_many通过表单和添加属性来连接表

这是我的第一个stakoverflow问题,对Rails来说还算新。 我搜索过以前的类似问题,但似乎无法想出这个问题。 我有一个与用户和帐户的has_many关系,我在UserAccount模型(连接表)上有一个额外的布尔属性“account_admin”。 我正在尝试在创建新帐户时弄清楚如何设置它。 用户: class User :destroy has_many :accounts, :through => :user_accounts .. end 帐户: class Account :destroy has_many :users, :through => :user_accounts end 用户帐号: class UserAccount < ActiveRecord::Base belongs_to :user belongs_to :account # includes account_admin boolean end 我希望能够创建一个帐户,将用户分配到该帐户,并在一个表单中指定一个account_admin。 到目前为止我有这个允许我选择帐户中的用户,但我不知道如何在这里设置account_admin布尔值。 = simple_form_for @account do |f| = f.input :name = f.input :description = f.association :users, […]

在Rails应用程序中使用带有simple_form的twitter bootstrap时,如何将下拉列表风格化?

我正在使用simple_form和twitter-bootstrap-rails gems。 每件事情都运行良好,但不知何故下拉不是通过twitter bootstrap rails设计风格..它显示像普通forms。 [“one”, “two”, “three”, “four”], :input_html => {:class => ‘dropdown’}, :label => ‘Send To’, prompt: “Choose From List” %> DROPDOWN SHOWING图片: 在BOOTSTRAP中需要降落的图像

使用Rails保存之前将字符串转换为日期

对Ruby很新,我已经被困了几个小时。 到处搜索,找不到答案。 所以我正在使用rails gem的bootstrap datepicker。 因为我已经更改了日期选择器的日期格式,所以它不会存储在数据库中。 猜测这是因为simple_form输入被用作字符串以避免simple_form应用的默认日期选择输入。 我的问题是:如何将“06/18/2013”​​之类的字符串修改/转换为保存到数据库之前的日期? 这最好由控制器处理吗? 我的控制器: # PUT /events/1 # PUT /events/1.json def update @event = Event.find(params[:id]) # Ugghhhh I need help # @event.event_date = Date.parse(params[:event_date]).to_date respond_to do |format| if @event.update_attributes(params[:event]) format.html { redirect_to @event, :notice => ‘Event was successfully updated.’ } format.json { head :no_content } else format.html { render […]

带有Bootstrap的simple_form复选框

我正在使用带有Bootstrap的simple_form,我希望我的“记住我”复选框位于标签的左侧,如Twitter Bootstrap文档中所示: http : //twitter.github.com/bootstrap/base- css.html#forms 我的表单代码如下所示: resource_name, :url => session_path(resource_name), :html => { :class => ‘well’}) do |f| %> :boolean if devise_mapping.rememberable? %> 结果是复选框顶部的“记住我”标签。 我搞砸了什么?

Grouped Collection选择按字母顺序排列的Rails

我终于想出了如何使用本教程实现动态选择菜单。 一切正常,但是如何按名称组织下拉列表中的城市…. 以下是我写的所有代码。 (如果您需要任何进一步的信息,请告诉我) 新的铁路请帮助:) VIEWS “Select a State”}, {:class=>’dropdown’} %> ### I would like the order of the cities displayed in the drop down to be alphabetized “Select a City”}, {:class=>’dropdown’} %>

Cocoon添加关联,如何限制关联数量

我正在创建一个使用Ruby / Rails / HAML存储卡的系统 – 在这种情况下,有一个Card类有很多颜色(这也是一个类)。 在创建和编辑卡片时,我正在使用Cocoon gem来动态添加颜色关联。 我遇到的问题是,在卡片模型中,卡片最多只能有5种颜色。 然而,界面允许添加无限的颜色,从而导致错误。 在Cocoon中是否有办法限制可以添加到表单的关联数量,以便不超过此限制? 这是添加/编辑卡片的表单代码 = simple_form_for @card, multipart: true do |c| = c.input :name, label: “Name of the card” = c.input :cost, label: “Cost of the card” #colours = c.simple_fields_for :colours do |colour| = render “colour_fields”, f: colour .links = link_to_add_association ‘add colour’, c, :colours 这是colour_fieldsforms […]