simple-form

Give form a CSS class using simple_form_for

不打扰是莪最后的温柔 提交于 2019-11-29 01:50:40
问题 Here's what I've tried, and the simple_form_for call ignored my class setting. # 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"> Any suggestions? 回答1: this would work <%= simple_form_for @admin_artist, :html=> { class: 'foobarbaz' } do |f| %> 回答2: You should use :html like this: <%= simple_form

Rails Simpleform with non-model inputs

点点圈 提交于 2019-11-29 01:23:18
I have a normal form using simpleform. Now I'd like to add an input that does not have any corresponding field in the model, it will be processed by the controller. I tried <%= simple_form_for @obj do |f| %> <%= f.input :name %> <%= f.input :attr, as: :string %> <-- should just send "attr" as post data <% end %> but this gives a Method not found: attr_not_in_obj error. I could obviously use the standard rails helpers, but then I will miss all of the simpleform HTML around the input, and copying doesn't quite seem right. In short: I'm looking for something like simpleform version of rails tag

how to change class of a label for checkboxes in simple_form

和自甴很熟 提交于 2019-11-28 21:07:34
using simple_form we can change class of a label using: label_html => {:class => "myclass"} but how do we do the same when dealing with checkboxes? simple_form assigns the default class of collection_check_boxes Is there a way to change this default class? I wanted to give an update to this answer in case someone comes here looking for a way to do this as I did. You can give the label a class with this option :item_wrapper_class => 'class_goes_here' Here is a full example: = user.input :resident, :collection => [["In the U.S", true],["Outside the U.S.", false]], :label_method => :first, :value

rails, simple_form, how to set selected index of a collection when page loaded?

扶醉桌前 提交于 2019-11-28 21:00:29
I am using simple_form gem, I have a countries collection, it work fine when I select the country, and updated record will have the country id stored, but, when I try to edit the record, the chosen country is not selected by default at edit form. Here is the code at edit form: = f.input :country_id, :collection => all_countries Shouldn't simple_form view the selected country from the db ? Have you tried to use the :selected => option? :selected => selected_country_id So, = f.input :country_id, :collection => all_countries, :selected => selected_country_id This will work perfectly !!! Cheers! I

How to apply tags with acts_as_taggable_on using check boxes?

爱⌒轻易说出口 提交于 2019-11-28 20:40:51
问题 I would like to assign two different "types" of tags (sector categories and free tagging) to a Company model using acts_as_taggable_on. NB: I'm new to RoR! This is easy to do if just using standard text input fields, but I would like to use check-boxes on one type (a fixed sector category tag that is predefined), and then allow the user to add comma separated tags in an input field. I have played around with this problem in various ways,... one inspired by this question...but I cannot get it

Styling file upload button for simple_form_for with Bootstrap in Rails 3

帅比萌擦擦* 提交于 2019-11-28 20:36:33
问题 Using simple_form_for, Bootstrap and Rails 3. In a form: <%= f.input :upload, label: 'PDF file:' , input_html: {accept: ('application/pdf') } %> I don't know how I'd style this so that the "choose file" button can have a different class ('btn btn-primary'). Additionally, when using with Bootstrap at least, its severely misaligned by default. See attached image. Finally, how do I redefine the text from "No file chosen" to "Chose file" when there isn't one added yet, and show the file name when

Rails: Using simple_form and integrating Twitter Bootstrap

会有一股神秘感。 提交于 2019-11-28 16:48:54
问题 I'm trying to build a rails app and simple_form looks to be a really useful gem. Problem is that I am using twitter bootstrap css to do the styling and the simple_form doesn't allow you to specify the layout of the html. Can anyone tell me how I can conform the simple_form html into the format bootstrap css wants? 回答1: Note: This answer only applies to SimpleForm < 2.0 Start with this in config/initializers/simple_form.rb : SimpleForm.form_class = nil SimpleForm.wrapper_class = 'clearfix'

Does form_tag work with Simple_form?

主宰稳场 提交于 2019-11-28 16:40:35
I have a form that is using form_tag and not sure how to use it with the simple_form gem . This is how my form looks: <%= form_tag create_multiple_prices_path, :method => :post do %> <% @prices.each_with_index do |price, index| %> <%= fields_for "prices[#{index}]", price do |up| %> <%= render "fields", :f => up %> <% end %> <% end %> <%= submit_tag "Done" %> <% end %> Can it be done? How would a form_tag change to use simple_form correctly? What about when using it with fields_for ? A Newbie could use some help. Thank you. simple_form is a wrapper around form_for , not form_tag . You can use

Rails 3.1+ Nested Forms Issue: Can't mass-assign protected attributes

半世苍凉 提交于 2019-11-28 14:24:28
I have a basketball app, where a Roster has many Players, and a Player can be on multiple Rosters.(Reason for many-to-many is for a Player-Roster archive) Roster.rb class Roster < ActiveRecord::Base belongs_to :team has_many :rosterizes has_many :players, :through => :rosterizes accepts_nested_attributes_for :players attr_accessible :jersey_number, :team_id, :class_year, :players end Rosterizes.rb (poorly named I know...) class Rosterize < ActiveRecord::Base belongs_to :player belongs_to :roster attr_accessible :player_id, :roster_id end Player.rb class Player < ActiveRecord::Base has_many

Simple_form adding class to form

核能气质少年 提交于 2019-11-28 11:55:35
I am using simple_form in my Rails application, I tried to add form-horizontal class to my form. <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"> When I use html: { class: "form-horizontal" } it change class="simple_form new_order" to class="simple_form form-horizontal" . What should I do to keep new_order class? Vasiliy Ermolovich It's intended behaviour . So if you want to change it you should monkey-patch simple_form_css_class method in this file . it