simple-form

Is there a way to submit ajax/json requests with simple_form for Rails

心不动则不痛 提交于 2019-11-30 20:13:43
With the standard Rails form_for, I was able to pass ajax requests though select and collection_select helpers as such: <%= address.collection_select :country, @countries, :id, :name, {:include_blank => false}, "data-remote" => true, "data-url" => "/ajax/states", "data-type" => :json %> I can't seem to figure out how to do this with simple_form Figured it out. You just need to add the this: :input_html => {"data-remote" => true, "data-url" => "/yoururl", "data-type" => :json} It is better to write it like this: = simple_form_for sample_result, url: reject_sample_result_path(sample_result),

Rails - Custom html into simple_form label

独自空忆成欢 提交于 2019-11-30 17:29:33
I'm trying to customize the output of a simple_form association, basically I need to display a checkbox label on two lines. My idea was adding a "br" tag into the "label", but unfortunately it gets escaped so it display actually "br" instead of going to a new line I use a lambda for customizing the label output <%= f.association :item, :as => :check_boxes, :collection => current_user.items, :label => false, :label_method => lambda { |item| "#{item.city.capitalize},<br> #{item.address}" }%> this produces an escaped br into the label string, how could I display the label on two lines? call html

Rails - Custom html into simple_form label

杀马特。学长 韩版系。学妹 提交于 2019-11-30 16:38:33
问题 I'm trying to customize the output of a simple_form association, basically I need to display a checkbox label on two lines. My idea was adding a "br" tag into the "label", but unfortunately it gets escaped so it display actually "br" instead of going to a new line I use a lambda for customizing the label output <%= f.association :item, :as => :check_boxes, :collection => current_user.items, :label => false, :label_method => lambda { |item| "#{item.city.capitalize},<br> #{item.address}" }%>

How to use placeholders instead of labels in simple_form?

青春壹個敷衍的年華 提交于 2019-11-30 11:00:57
I want to use placeholders everywhere in my application instead of labels. I am using simple_form and Rails (3.2.14). How can I specify in simple_form config file to use placeholders instead of labels. In Initializers there is a file simple_form.rb ie # 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

Simple form association custom label name

孤街浪徒 提交于 2019-11-30 10:38:22
问题 I have been struggling with what I perceive to be a simple problem: Working in Rails 3.0.8 with the simple_form 1.4 gem. I have two models, owners and owner_types; class Owner < ActiveRecord::Base belongs_to :own_type attr_accessible :name, :own_type_id end class OwnerType < ActiveRecord::Base has_many :owners attr_accessible :name, :subtype_name end In my the _form partial of the Owner view, I want to have a select box that displays both the name and subtype_name of the owner_type

Deep Nested Rails 4 Form

我们两清 提交于 2019-11-30 09:05:52
I have 3 models Item which accepts nested attributes for questions and questions accept nested attributes for answers. I'm trying to create an item which has a question and an answer in the same form. item.rb class Item < ActiveRecord::Base has_many :questions, dependent: :destroy accepts_nested_attributes_for :questions end question.rb class Question < ActiveRecord::Base belongs_to :item has_many :answers, dependent: :destroy accepts_nested_attributes_for :answers end answer.rb class Answer < ActiveRecord::Base belongs_to :question end item_controller.rb class ItemsController <

Simple_form how to make accept terms checkbox inline

十年热恋 提交于 2019-11-30 08:59:45
<p><%= f.input :terms, :as => :boolean, :label => false, :boolean_style => :inline %> Accept <%= link_to "Terms of use", terms_path,:remote => true %> and <%=link_to "privacy Policy", privacy_path, :remote => true%></p> It ends up looking like this What is the best way to line them up on the same line. Here's a rather simple way: <%= content_for(:the_links) do %> Accept <%= link_to "Terms of use", terms_path,:remote => true %> and <%=link_to "privacy Policy", privacy_path, :remote => true%> <% end %> <%= simple_form_for @user do |f| %> <%= f.input :email %> <%= f.input :password %> <%= f.input

Display inline errors with simple_form in a Bootstrap Ajax modal

蓝咒 提交于 2019-11-30 07:37:58
问题 I've found similar StackOverflow questions here and here but still can't get this to work. I'm using Rails 3.2.8, SimpleForm 2.0.4, and Twitter Bootstrap 2.1.1 (via the bootstrap-sass gem 2.1.1.0). The user should be able to add a contact from a modal popup window. If there are validation errors, they should appear inline, just as if the user were using a non-modal version of the form (red border around field, error message next to field). I load the modal like this: <a data-toggle="modal"

How do I add HTML attributes to select options with Simple Form Rails?

久未见 提交于 2019-11-30 05:56:58
I need to add a custom HTML attribute to each option for a select control. I'm using simple_form in Rails. Does anyone know how to do this? The attribute will be consumed by client-side JS. For instance, I want to do something like this: <%= f.input :group, collection: @groups, option_html: { data-type: lambda { |g| g[2] } } %> Which would produce (simplified): <select> <option value="1" data-type="primary">First Group</option> <option value="2" data-type="secondary">Second Group</option> <option value="3" data-type="secondary">Third Group</option> </select> Where @groups might look like this:

Rails acts-as-taggable-on with select2 (and simple_form)

放肆的年华 提交于 2019-11-30 05:09:06
问题 I would like to have a select2 dropdown of tags, where i could select multiple existing tags and add new ones. I have tried many different ways and i either don't get select2 box working or only one value is passed (last one). This is closest i got (passes last value): <%= f.input :tag_list, collection: @model.tags.map { |t| t.name }, input_html: { :style=> 'width: 300px', class: "taggable", data: { placeholder: "Tags" }} %> 回答1: As I mentioned before, normal select2 library now uses only