有没有办法告诉Rails不要div.field_with_errors在标签和实际字段div.error周围创建,而是围绕它们创建?
例如,我在表格中的片段(用HAML编写)
= form_for @user do |f|
%div.clearfix
= f.label :name
%div.input
= f.text_field :name
Run Code Online (Sandbox Code Playgroud)
我希望在错误的情况下根目录div div.clearfix.error并避免这种情况field_with_errors.我可以这样做吗?
作为另一种选择,我可以制作formtastic 来创建Bootstrap -styled元素,没有formtastic的css和html类,但是使用bootstrap的.在使用formtastic的情况下,我可以使用错误字段制作一些东西吗?
customization ruby-on-rails formtastic ruby-on-rails-3 twitter-bootstrap
我有一个表单,我正在尝试设置...用户可以有很多帖子,每个帖子都可以有很多人观看它.
Watch模型以多态形式设置为"可观察",因此它可以应用于不同类型的模型.它具有user_id,watchable_id,watchable_type和时间戳作为属性/字段.
这是非常好的,所以当人们评论帖子时,观看帖子的用户可以收到有关它的电子邮件.
我要做的是向用户显示他们可以在每个帖子上标记的用户列表,这不是问题.这就是我现在正在使用的
<% semantic_form_for @update do |f| %>
<%= f.input :subject, :input_html => { :class => 'short' } %>
<%= f.input :site, :include_blank => false, :input_html => { :class => 'short' } %>
<label>Tag Users (they will get notified of this update)</label>
<%= f.input :user, :as => :check_boxes, :label => ' ', :wrapper_html => { :class => "radiolist clearfix" }, :for => :watch, :name => "Watch" %>
<%= f.input :note, :label => 'Update'%>
<% f.buttons do %>
<%= …Run Code Online (Sandbox Code Playgroud) 我有:
form.input :duration, as: select, collection: {}
Run Code Online (Sandbox Code Playgroud)
我需要:
<option value="" data-price="XXX"></option>
Run Code Online (Sandbox Code Playgroud)
Rails不支持选项标记的HTML5数据属性.Formtastic 建议为此创建一个辅助方法.
Formtastic自述文件描述了如何扩展输入标签.但是,在select_input.rb中,我找不到任何会影响option标签的方法.那么,我该怎么做?
此外,我发现enhanced_select gem正是我所需要的,但我无法使其与formtastic一起工作.
我在Rails 3.2(使用Active Admin)中使用Formtastic 2.1.1,我想在我的表单中插入一行,但没有输入字段.这是可能的吗?Formtastic DSL中的语法是什么来实现这一目标?
这是一个例子:
form do |f|
f.inputs "Model Info" do
f.input :title
f.input :published
f.input :path
end
end
Run Code Online (Sandbox Code Playgroud)
我想做这样的事情:
form do |f|
f.inputs "Model Info" do
f.input :title
f.input :published
f.input :path
f.div "This is some important text that people using this form need to know"
end
end
Run Code Online (Sandbox Code Playgroud)
有没有人以前用Formtastic做过这件事?
我希望用Formtastic重现以下内容:
<% form_tag '/search', :method => 'get' do %>
<%= text_field_tag :q, params[:q] %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
到目前为止,我有:
<% semantic_form_for :search, :html => { :method => :get } do |form| %>
<% form.inputs do %>
<%= form.input :q %>
<% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
但是,这需要使用以下方法访问参数哈希:
params[:search][:q]
Run Code Online (Sandbox Code Playgroud)
而不是我的要求:
params[:q]
Run Code Online (Sandbox Code Playgroud)
我想在我正在处理的应用程序中使用Formtastic用于所有表单,到目前为止我只遇到过这个问题.有任何想法吗?
我试图在嵌套表单中的文件字段上使用HTML5多重属性.
模型如下:
class Album < ActiveRecord::Base
has_many :album_images
has_many :images, :through => :album_images
accepts_nested_attributes_for :images
end
class Image < ActiveRecord::Base
has_many :album_images
has_many :albums, :through => :album_images
mount_uploader :filename, ImageUploader
validates_presence_of :filename
end
Run Code Online (Sandbox Code Playgroud)
风景:
<%= semantic_form_for @album, :url => upload_path do |f| %>
<%= f.inputs do %>
<%= f.input :name, :label => 'Album title' %>
<% end %>
<%= f.input :images, :as => :file, :input_html => {:multiple => true} %>
<%= f.buttons do %>
<%= f.commit_button 'Upload' %>
<% end …Run Code Online (Sandbox Code Playgroud) 我开始使用formstatic,但我需要创建一个带有图像预览的文件字段.我的意思是,当我编辑一个对象时,我希望看到已经链接的图像.
我怎样才能做到这一点?
谢谢 !
我使用Ruby on Rails的精湛的Formtastic插件.
在使用自定义集合时,有人知道如何包含空格(选项)吗?
当我尝试:
<%= f.input :organizations, :collection => Organization.all(:order => :name), :include_blank => true %>
Run Code Online (Sandbox Code Playgroud)
我得到了收藏的选择框,但不是空白...
我需要将一个集合传递给Formtastic中的标准选择输入:
f.input :apple, :as => :select, :collection => Apple.all
Run Code Online (Sandbox Code Playgroud)
问题是,虽然我需要Formtastic来访问与名称不同的方法.现在这确实是一个问题.我总是可以传递数组
f.input :apple, :as => :select, :collection => Apple.map { |a| a.format_name }
Run Code Online (Sandbox Code Playgroud)
问题是,在此之后,我将在控制器中获取字符串而不是不需要的ID.我试图传递Hash:
options = Hash.new
Apple.each { |a| Apple.store(a.format_name, a.id) }
f.input :apple, :as => :select, :collection => options
Run Code Online (Sandbox Code Playgroud)
现在问题是,因为我使用的是Ruby 1.8.7,所以Hash命令是未指定的,我当然需要有序输入...
我可以想象一些解决方案,但所有这些都需要不必要的代码.
知道怎么解决这个问题吧?
我使用Active admin,我需要上传带有大量图片的画廊.我该怎么做?我的代码:
class Gallery < ActiveRecord::Base
belongs_to :event
has_many :images
attr_accessible :name, :publish, :images, :image, :images_attributes
accepts_nested_attributes_for :images, allow_destroy: true
validates :name, presence: true
end
class Image < ActiveRecord::Base
belongs_to :gallery
attr_accessible :url
has_attached_file :url, :styles => { :medium => "300x300>", :thumb => "100x100>" }
end
ActiveAdmin.register Gallery do
form html: { multipart: true } do |f|
f.inputs do
f.input :name
f.input :images, as: :file, input_html: { multiple: true}
end
f.buttons
end
end
Run Code Online (Sandbox Code Playgroud)
我有这个错误:
Image(#70319146544460) expected, got ActionDispatch::Http::UploadedFile(#70319105893880)
Run Code Online (Sandbox Code Playgroud)