标签: simple-form

有没有办法使用simple_form for Rails提交ajax/json请求

使用标准的Rails form_for,我能够通过select和collection_select帮助程序传递ajax请求:

<%= address.collection_select :country, @countries, :id, :name, {:include_blank => false}, "data-remote" => true, "data-url" => "/ajax/states", "data-type" => :json  %>
Run Code Online (Sandbox Code Playgroud)

我似乎无法弄清楚如何使用simple_form来做到这一点

ajax ruby-on-rails simple-form

7
推荐指数
3
解决办法
2万
查看次数

SimpleForm + ClientSideValidations + bootstrap - 表单上没有验证 - 所有输入都被接受

我在RoR应用程序中使用SimpleForm,ClientSideValidations和ClientSideValidations-SimpleForm gems.我可以将表单精美地渲染到模态中,但是当输入失去焦点时,不会发生验证并提交表单.另请注意,我尝试使用此处的修复程序:http: //www.ddarrensmith.com/blog/2012/05/17/ruby-on-rails-client-side-validation-with-validation-helpers-and- Twitter的引导/

包含表单的视图的片段:

<div class='modal hide' id='New_Discrep' tabindex="-1" role='dialog' aria-labelledby="#New_Discrep_Label" aria-hidden='true'>
  <div class="modal-header">
    <button type='button' class='close' data-dismiss='modal' aria-    hidden='true'>x</button>
    <h3 id="New_Discrep_Label">Create Discrepancy</h3>
  </div>
  <%= simple_form_for @new_discrepancy, :validate => true, :url => {:controller=> 'discrepancy', :action => 'create', :device_id => @device.id} do |f| %>
  <div class='modal-body'>
    <%= f.input :system, :wrapper => :prepend, :label => false do %>
      <%= content_tag :span, 'System', :class => 'add-on input-label' %>
      <%= f.input_field :system %>
    <% end %>
    <%= f.input :description, :wrapper => …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails client-side-validation simple-form twitter-bootstrap

7
推荐指数
1
解决办法
3654
查看次数

Bootstrap +简单形式复选框网格

我有一个20多个标签的列表,我想在4列复选框网格中呈现,但我不太确定最干净的方法是什么.我有以下表格:

= simple_form_for(@fracture) do |f|
  = f.error_notification    
  .form-inputs
    = f.input :title
    = f.input :summary
    = f.input :tag_list, :as => :check_boxes, :collection => ActsAsTaggableOn::Tag.all.map(&:name), :item_wrapper_class => 'inline'
Run Code Online (Sandbox Code Playgroud)

结果表格应该是这样的http://jsfiddle.net/LVFzK/,但我想将逻辑限制在一个wrapper或CSS中,而不是手动修改HTML.

css css3 simple-form twitter-bootstrap

7
推荐指数
1
解决办法
8915
查看次数

为什么在OSX中的select选项上使用`-webkit-appearance:none`会使文本消失?

为了在OS X中的Chrome上获得我想要的样式,我必须使用该-webkit-appearance: none;属性.

看到这个问题这个答案.

问题是,现在当我选择一个答案时,它没有显示出来.该领域仍然是空白.

这是没有该属性的外观:

没有属性

这是它与属性的外观:

有了属性

对于它的价值,这就是我创建这个选择菜单的方式 - 使用Simple Form:

<%= f.input_field :country_id, collection: Piggybak::Country.send(type), class: "required" %>
Run Code Online (Sandbox Code Playgroud)

这是它生成的HTML:

<select class="select required required valid" id="piggybak_order_billing_address_attributes_country_id" name="piggybak_order[billing_address_attributes][country_id]"><option value=""></option>
<option value="231" selected="selected">United States</option></select>
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

编辑1

这是CSS:

form.simple_form select {
    padding: 20px;
    -webkit-appearance: none;
}
Run Code Online (Sandbox Code Playgroud)

css ruby-on-rails css3 simple-form

7
推荐指数
2
解决办法
3万
查看次数

使用simple_form Rails时测试HTML 5表单验证

我正在为我的待办事项列表应用程序使用devise和simple_form.现在,我的用户/ edit.html.erb有以下代码

<%= content_for :title,'Edit profile' %>
<h2>Edit profile</h2>
<%= simple_form_for current_user, class: 'form-horizontal' do |f| %>
  <%= f.input :nick_name %>
  <%= f.submit 'Update profile' %>
<% end %>
Run Code Online (Sandbox Code Playgroud)

我的user.rb看起来像这样:

class User < ActiveRecord::Base  
 devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable
 attr_accessible :email,:nick_name, :password, :password_confirmation, :remember_me
 validates :nick_name, presence: true    # the other fields already validated by devise
 has_many :lists , dependent: :destroy
end
Run Code Online (Sandbox Code Playgroud)

现在,当我点击带有空nick_name字段的提交按钮时,我会得到一个弹出式警报.它不像普通的浏览器警报,我认为它是一个HTML5功能.我将此消息Please fill out this field作为空字段下方的弹出窗口.我已禁用javascript,但它仍显示相同的消息.这是我的nick_name输入字段:

<input class="string required" id="user_nick_name" name="user[nick_name]" required="required" size="50" type="text">
Run Code Online (Sandbox Code Playgroud)

现在,当我在模型中删除nick_name的状态验证时,此弹出窗口不会出现.当验证行被注释掉时, …

capybara ruby-on-rails-3 simple-form

7
推荐指数
2
解决办法
2042
查看次数

使用嵌套表单时,无法批量分配受保护的属性设计错误

我搜索了很长时间,但找不到解决方案.这是我的模特:

web.rb

class Web < ActiveRecord::Base
   devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

  attr_accessible :email, :password, :password_confirmation, :user_type, :remember_me

  belongs_to :role, :polymorphic => true
end
Run Code Online (Sandbox Code Playgroud)

user.rb

class User < ActiveRecord::Base
 has_one :web, :as => :role
 attr_accessible :dob, :fname, :lname
end
Run Code Online (Sandbox Code Playgroud)

org.rb

class Org < ActiveRecord::Base
  has_one :web, :as => :role
  attr_accessible :name, :website
end
Run Code Online (Sandbox Code Playgroud)

一切似乎没问题,直到我在devise/registration/new.html.erb中使用simple_form_for而不是普通的form_for

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :class => 'form-horizontal' }) do |f| %>

  <%= f.input :email, label: false, :input_html => …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails devise simple-form

7
推荐指数
1
解决办法
512
查看次数

Simple_form:为什么生成两个输入标签而不是一个?

为什么simple_form为布尔字段生成两次输入标记(一个隐藏,另一个不隐藏)?

在我的simple_form中,我有这个:

<%= form.input :over_phone, as: :boolean, input_html: {checked: true} %>

产生这个:

<div class="control-group boolean optional order_over_phone">
  <label class="boolean optional control-label" for="order_over_phone">Order over phone</label>
  <div class="controls">
    <input name="order[over_phone]" type="hidden" value="0">
    <label class="checkbox">
      <input checked="checked" class="boolean optional" id="order_over_phone" name="order[over_phone]" type="checkbox" value="1">
    </label>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

如您所见,一个输入标记被隐藏,值为0,另一个输入标记被取消隐藏,值为1.如果我提交表单,在post参数中我得到两个值:

order[over_phone]:0
order[over_phone]:1
Run Code Online (Sandbox Code Playgroud)

我在与此布尔字段关联的模型创建中有一些随机行为,所以我想知道它是否是由simple_form引起的.非布尔字段类型不会发生这种情况.

如果您遇到类似问题,请分享您的经验.

我正在使用simple_form 2.1.0.

ruby-on-rails form-helpers simple-form

7
推荐指数
1
解决办法
1083
查看次数

Rails simple_form,在输入之前移动提示

无论如何移动提示组件使其出现在输入之前?

当前显示的组件按以下顺序显示:标签,输入,提示,错误.我尝试添加:components选项,但这不起作用.

这是我的代码:

<%= f.input :content, 
            :components => [:label, :hint, :input], 
            :as => :text, 
            hint: 'Please 1) include your exact copy here, 2) upload your copy document in the next step, or 3) describe any content services to include in our estimate.', 
            required: true, 
            :label => "Copy" %>
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails simple-form

7
推荐指数
2
解决办法
4776
查看次数

简单形式单选按钮

我正在使用simple_form gem并且非常喜欢它的简单性.但是,尝试设置设置一个简单的单选按钮超出了我,因为我不断收到以下错误

"未定义的局部变量或方法`素食主义者'"

这是我到目前为止所拥有的

 <%= f.collection_radio_buttons :diettype, [[vegan, 'vegan'] ,[vegetarian, 'vegetarian']]%>
Run Code Online (Sandbox Code Playgroud)

2.使用我在simple_form之前使用的代码和更新/补丁方法,它将更新并保存用户需求

 <%= f.label(:diettype, "Vegan") %>
 <%= f.radio_button(:diettype, "Vegan") %>
 <%= f.label(:diettype, "vegetarian") %>
 <%= f.radio_button(:diettype, "vegetarian")%>
Run Code Online (Sandbox Code Playgroud)

3.这就是我想要重现的东西

<select>
   <option> vegan </option>
   <option> Vegetarian </option>
</select>
Run Code Online (Sandbox Code Playgroud)

注意 - 素食主义者和素食主义者是选择的选项,将存储在以下数据库列中:diettype.

ruby-on-rails simple-form

7
推荐指数
2
解决办法
1万
查看次数

如何在simple_form中处理人员身高?

我有一个Profile具有height属性的模型.

我需要存储用户的高度(也就是配置文件),但我不太清楚如何做到这一点.我认为最好的方法是将选择下拉列表分解为英寸(即4'0",4'1"...... 6'5"等).但我不太确定最好的方法将其存储在数据库中.

我认为最简单的存储英寸,但如果我这样做,我如何以我上面指定的格式在我的选择中显示高度.

现在,我只有一个整数字段:

<%= f.input_field :height, placeholder: "176", class: 'col-lg-9 form-control' %>
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails simple-form ruby-on-rails-5

7
推荐指数
1
解决办法
501
查看次数