simple-form

How can I generate input[type=date] with simple_form?

我们两清 提交于 2019-12-06 06:03:24
问题 When I do f.input :start_date, as: :date I get 3 select elements (day, month and year). I can do f.input :start_date, as: :string to get input[type=text] element, but how can I generate input[type=date] element with simple_form? 回答1: You should specify html5 option: f.input :start_date, as: :date, html5: true Here is details. 回答2: HTML 5 date / time inputs are not generated by Simple Form by default, so using date, time or datetime will all generate select boxes using normal Rails helpers. We

How can I elegantly construct a form for a model that has a polymorphic association?

自闭症网瘾萝莉.ら 提交于 2019-12-06 04:34:13
问题 Here are my models: class Lesson < ActiveRecord::Base belongs_to :topic, :polymorphic => true validates_presence_of :topic_type, :topic_id end class Subject < ActiveRecord::Base has_many :lessons, :as => :topic end class Category < ActiveRecord::Base has_many :lessons, :as => :topic end Now, what I need is a form that will allow the user to create or update Lessons. The questions is, how can I provide a select menu that offers a mix of Subjects and Categories? (To the user, on this particular

Add a class to each select options with SimpleForm

大憨熊 提交于 2019-12-06 03:44:47
I want to build a select input from an array (and not a collection of models), with SimpleForm, and have different classes for each option s. I would have hoped that this would work: f.input :method, collection: [ ["option text", "option_value_1", { class: "class_name_1" }], ["option text 2", "option_value_2", { class: "class_name_2" }] ] The problem with that is it will generate: <select> <option value="option text" class="class_name_1">option text</option> <option value="option text 2" class="class_name_2">option text 2</option> </select> How can I do what I want (value should be "option

Rails: Conditional path in form partial

霸气de小男生 提交于 2019-12-05 21:07:32
I have two forms for new and edit that I want to extract to a partial, but, to my begginer knowledge in Rails, they need different paths in order to work. This is my edit form: <%= simple_form_for [@user, @wiki], url: user_wiki_path do |f| %> <%= f.input :title %> <%= f.input :body %> <%= f.submit class: "btn btn-success" %> <% end %> This is my new form: <%= simple_form_for [@user, @wiki], url: user_wikis_path, method: :post do |f| %> <%= f.input :title %> <%= f.input :body %> <%= f.submit class: "btn btn-success" %> <% end %> Can I, and if so, how, combine them into one partial _form.html

Foundation 5, Simple Form and Rails - how to get 'hints' CSS class working

坚强是说给别人听的谎言 提交于 2019-12-05 20:45:32
I have been searching for days and experimenting, but I am unable to get the Simple Form gem hints CSS class to show. This is simply a class to show a hint for a form input when you hover over it. I am using Rails 4.1 with the latest simple_form gem and foundation 5. I have uncommented the line b.use :hint, wrap_with: { tag: :span, class: :hint } The CSS shows the hint that I have included in the form wrapped in a Span class="hint", but the CSS I have provided for the class is not applied. The CSS for this (actually it's SCSS) is: .simple_form { .error { clear: left; color: black; display:

simple form collection translation

懵懂的女人 提交于 2019-12-05 19:33:10
Using the translation example here that translates the :male, :female options using Ruby I18n, the form will be: View: _form.html.erb <%= f.input :gender, collection: [:male, :female] %> Generated HTML: <option>Male</option> <option>Female</option> So when submitting, the form uses the translated values. How can I change the view code to submit ["male", "female"] values instead of ["Male", "Female"]? My best shot so far is pretty ugly: <%= f.input :gender, collection: [:male, :female].map{|v| [t("simple_form.options.user.gender.#{v.to_s}", v] %> In your view, you should just use <%= f.input

Prepended input label (simple_form + bootstrap-sass) off by a few pixels

二次信任 提交于 2019-12-05 18:16:04
I want to use the text input field seen here: http://simple-form-bootstrap.plataformatec.com.br/articles/new (It's the second text input field on that page.) I have it working in other Rails apps but for some reason in my current one there is a several-pixel gap between the prepended label and the text input. I've installed simple_form with the --bootstrap option, and have verified that the Rails/haml/bootstrap/bootstrap-sass versions are the same as the working rails app. I don't override any of the related css in my stylesheets (I commented it all out to be sure). Any ideas why Bootstrap isn

How to list all countries in select using country_select gem with simple_form

好久不见. 提交于 2019-12-05 17:22:50
I have added gem 'country-select' to my gemfile, and I need to list all countries in a select. I try <%= f.input :country, as: :select %> but countries don't appear. There are no info about that in documentation. Please help me with this issue. try this out <%= f.input :country, as: :country %> 来源: https://stackoverflow.com/questions/18302078/how-to-list-all-countries-in-select-using-country-select-gem-with-simple-form

Rails Simpleform setting the width of a form input element

人走茶凉 提交于 2019-12-05 15:41:29
I'm using the gem simpleform inside a table I want to adjust the width of each form element of the simple form can I do that? I tried the following but it doesn't seem to work <td><%= listing.name %></td> <td><%= f.input :suite, :input_html => { :size => 10, :maxlength => 10 } %></td> I looked at the simpleform documentation here but couldn't find how to specifically set the width. Here is what my form inside a table looks like. I'd like to make the columns narrower. As you can see the column widths are very wide. Please advise how to make them the appropriate size so they don't take too much

Adding controls inline with simple_form, nested_form and Twitter Bootstrap in Rails

本小妞迷上赌 提交于 2019-12-05 06:36:33
I'm using simple_form, nested_form and Twitter Bootstrap and trying to put the "Remove Link" from nested_form on the same line as the object. Right now it looks like this: http://grab.by/eKDS and I want it to look like this: http://grab.by/eKEc Here's what my code looks like: <%= cform.simple_fields_for :licensings do |lf| %> <%= lf.input :state, :collection => us_states, :wrapper => false %> <%= lf.link_to_remove "Remove this Licensing", :class => 'btn btn-mini btn-danger' %> <% end %> I've tried putting the second link_to_remove inside a block for the first lf.input but then the actual