如何在不与模型关联的情况下添加simple_form复选框?我想创建一个复选框,它将处理一些javascript事件,但不知道?也许我错过了文档中的内容?不要使用类似下面的类似:
= simple_form_for(resource, as: resource_name, url: session_url(resource_name), wrapper: :inline) do |f|
.inputs
= f.input :email, required: false, autofocus: true
= f.input :password, required: false
= f.input :remember_me, as: :boolean if devise_mapping.rememberable?
= my_checkbox, 'some text'
Run Code Online (Sandbox Code Playgroud) 如何将以下内容翻译成简单的表格?
<%= form_for(@bill) do |f| %>
<%= f.label :location_id %>
<%= f.collection_select(:location_id, @locations, :id, :location_name,
{:selected => @bill.location_id}) %>
Run Code Online (Sandbox Code Playgroud)
我不能使用简单的关联,因为@locations是where查询的结果.
我在我的应用程序中使用简单表单,并且我想删除*以指示我的所有表单(现有和尚未创建的表格)上都需要属性.
我试图进入simple_form.rb:
# Whether attributes are required by default (or not). Default is true.
config.required_by_default = false
Run Code Online (Sandbox Code Playgroud)
而且我试图修改simple_form.en.yml:
required:
text: 'required'
mark: '' # <------ tried setting this to blank.
Run Code Online (Sandbox Code Playgroud)
我知道我可以设置:required => false每个字段,但我想清理视图并设置一次.
我有一个simple_form,我试图在其中包含一个空白项,因为该字段中的'nil'值在此数据库中具有特殊含义.为了使最终用户更加明显,我还想用"(如果没有则选择)"这样的内容来标题.
我目前正在这样做,但它只在创建新对象时插入"空白"项目,而不是在编辑新对象时插入.
# _child_form.html.erb
<%= simple_form_for @child do |f| %>
<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.association :parent, :collection => @parents, :prompt => "(select if none)" %>
<%= f.button.submit %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
.
# child_controller.rb
def new
@child = Child.new
@parents = Parent.all
end
def edit
@child = Child.find(params[:id])
@parents = Parent.all
end
Run Code Online (Sandbox Code Playgroud) 这是我尝试过的,而且simple_form_for调用忽略了我的课堂设置.
# Rails code in view:
<%= simple_form_for @admin_artist, :class => 'foobarbaz' do |f| %>
# Renders:
<form accept-charset="UTF-8" action="/admin/artists" class="simple_form new_admin_artist" id="new_admin_artist" method="post" novalidate="novalidate">
Run Code Online (Sandbox Code Playgroud)
有什么建议?
使用rails 4,并尝试使用simple_form和paperclip将文件字段添加到现有表单.
这是表单的关键部分:
<%= simple_form_for(@employee, html: { class: 'form-horizontal requires', multipart: true}, remote: true) do |f| %>
<%= f.input :avatar %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
一切正常,除非我实际提交带有上传文件的表单.然后,我明白了:
ActionController::InvalidAuthenticityToken in EmployeesController#update
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?
我正在尝试构建一个rails应用程序,而simple_form看起来是一个非常有用的宝石.问题是我使用twitter bootstrap css来做样式,而simple_form不允许你指定html的布局.
谁能告诉我如何将simple_form html符合bootstrap css想要的格式?
我正在使用带有Bootstrap的simple_form,我希望我的"记住我"复选框位于标签的左侧,如Twitter Bootstrap文档中所示:http://twitter.github.com/bootstrap/base- css.html#形式
我的表单代码如下所示:
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => { :class => 'well'}) do |f| %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.input :remember_me, :as => :boolean if devise_mapping.rememberable? %>
<%= f.button :submit, "Sign In" %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
结果是复选框顶部的"记住我"标签.
我搞砸了什么?
所以我使用Simple Form for my Rails App,我需要摆脱简单表单附带的每个输入上的标签.
我试过:<%= f.input:email,class:"login-field",label:""%>将标签留空,但这不起作用.
我对rails很新,有人可以解释一下如何实现这个目标吗?
编辑:我正在尝试实现这种格式:
<input type="password" class="login-field" value="" placeholder="Password" id="login-pass" />
Run Code Online (Sandbox Code Playgroud)
谢谢.
在simple_form视图中,提交按钮如下所示:
<%= f.button :submit, 'Save' %>
Run Code Online (Sandbox Code Playgroud)
我们试图subaction在单击Save按钮时传递参数.在params[:subaction]点击该按钮后,应该有"更新"的价值.以下是我们在视图中尝试的但它不起作用:
<%= f.button :submit, 'Save', :subaction => 'update' %>
Run Code Online (Sandbox Code Playgroud)
有没有办法在params[:subaction]单击Save按钮时传递值?