所以我使用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按钮时传递值?
我想在我的应用程序中使用占位符而不是标签.我使用的是simple_form和Rails(3.2.14).如何在simple_form配置文件中指定使用占位符而不是标签.
在Initializers中有一个文件simple_form.rb即
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
# Wrappers are used by the form builder to generate a
# complete input. You can remove any component from the
# wrapper, change the order or even add your own to the
# stack. The options given below are used to wrap the
# whole input.
config.wrappers :default, :class => :input, :hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
## Extensions enabled …Run Code Online (Sandbox Code Playgroud) 我有一个simple_form输入字段,如下所示:
<%= f.input :particular_users, collection: @all_users, input_html: { class: 'multiselectuser', multiple: true} %>
Run Code Online (Sandbox Code Playgroud)
当我留下多个:true off时,表单提交参数的所选值:specific_users,我可以在使用"raise params.inspect"进行调试时看到该值.但是当我在那里留下multiple:true选项时,没有为参数传递值:special_users.
我究竟做错了什么?
编辑:我不能使用关联输入,因为:special_users是一个虚拟属性,没有任何关系.我希望多选框能够传递其中的任何值,即使它们是任意的.
我正在使用simple_form gem来创建Rails表单. http://github.com/plataformatec/simple_form
一切都很好,除了如何创建分组选择框?无法在文档中或谷歌搜索中找到它.
我在我的Rails应用程序中使用simple_form,我试图将form-horizontal类添加到我的表单中.
<form accept-charset="UTF-8" action="/account/orders" class="simple_form new_order" data-validate="true" enctype="multipart/form-data" id="new_order" method="post" novalidate="novalidate">
Run Code Online (Sandbox Code Playgroud)
当我使用html: { class: "form-horizontal" }它改变class="simple_form new_order"为class="simple_form form-horizontal".
我该怎么办才能new_order上课?
resources :users, shallow: true do
resources :shoes
end
Run Code Online (Sandbox Code Playgroud)
这给了我两个不同的创建和编辑路线
user_shoes_path
shoes_path
Run Code Online (Sandbox Code Playgroud)
在我的鞋子里,_form.html.erb如果我留下表格标签:url作为默认值,当我提交一个新的或更新的鞋子时,我得到一个丢失的路线错误.
如果我提供表单中的url,我可以将其用于新的或编辑更新,但我无法让它同时工作.
这适用于新的:
<%= simple_form_for :shoe, url: user_shoes_path do |f| %>
Run Code Online (Sandbox Code Playgroud)
这适用于编辑,但一旦尝试实际更新就会失败,因为它重定向到/:param_id:
<%= simple_form_for :shoe, url: shoes_path(@shoe) do |f| %>
Run Code Online (Sandbox Code Playgroud)
我怎样才能使它适用于两者?谢谢.
我有一个select字段,我想在其中放一个名为name的自定义属性,我试着这样做:
<%= f.association :in_charge, :collection => User.lawyer.map{ |l| [l.name, l.id, {:name => l.name.downcase}] } %>
Run Code Online (Sandbox Code Playgroud)
它工作并生成额外的属性,但是存在问题,选择值属性变为模型名称属性,在本例中为l.name.我更改了地方并首先放置了l.id但是显示了id属性,它们是重复的,任何想法为什么会发生这种情况?
是否有另一种方法可以在关联选择字段中定义自定义属性?
我正在尝试同时使用另一个嵌套资源创建一个资源.我正在使用Rails4和simple_form 3.0.0rc.这是我的代码.
class User < ActiveRecord::Base
has_one :profile
accepts_nested_attributes_for :profile
end
class Profile < ActiveRecord::Base
belongs_to :user
end
Run Code Online (Sandbox Code Playgroud)
class UsersController < ApplicationController
def new
@user = User.new
@user.build_profile
end
def create
user = User.new user_params
user.save
redirect_to root_url
# @par =params
end
private
def user_params
params.require(:user).permit(:email, profile_attributes: [:name])
end
end
Run Code Online (Sandbox Code Playgroud)
<%= simple_form_for @user do |f| %>
<%= f.input :email %>
<%= simple_fields_for :profile do |p| %>
<%= p.input :name %>
<% end %>
<%= f.submit %>
<% …Run Code Online (Sandbox Code Playgroud) ruby-on-rails nested-attributes fields-for simple-form strong-parameters
<%= f.association :opportunity_status, :label => "Status", :input_html => {} %>
<%= f.select :source_type, options_for_select(["lead","vteam"],["lead"]) %>
Run Code Online (Sandbox Code Playgroud)
在第一行,每件事都可以.在第二行,如果我按照我在第一行中的方式附加标签,则显示错误.
如何使用simpleform指定select的标签?