simple-form

Cocoon add association, how to limit number of associations

梦想与她 提交于 2019-12-18 04:16:31
问题 I am creating a system that stores cards using Ruby/Rails/HAML - In this case there is a Card class that has many Colours (this is also a class). When creating and editing a card I am using the Cocoon gem to allow me to dynamically add colour associations. The problem I am having is that in the Card model, a card is limited to having a maximum of 5 colours. Yet the interface allows adding of unlimited colours resulting in an error. Is there a way in Cocoon to limit the number of associations

How to set default selected value for Rails SimpleForm select box

我只是一个虾纸丫 提交于 2019-12-18 03:49:01
问题 I'm trying to figure out how to set the selected option of a select box generated by SimpleForm. My code is along the lines of: <%= simple_form_for(@user) do |f| %> <%= f.association :store, default: 1 %> Of course the default: 1 part does not work. TIA 回答1: Use the following: selected: 1 回答2: You can now use the following: <%= f.association :store, selected: 1 %> 来源: https://stackoverflow.com/questions/10441061/how-to-set-default-selected-value-for-rails-simpleform-select-box

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

左心房为你撑大大i 提交于 2019-12-17 23:14:48
问题 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 ? 回答1: Have you tried to use the :selected => option? :selected => selected_country_id So, = f.input

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

冷暖自知 提交于 2019-12-17 21:18:00
问题 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

Simple_form adding class to form

雨燕双飞 提交于 2019-12-17 19:57:52
问题 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? 回答1: It's intended behaviour. So if you

How to create a grouped select box using simple_form?

一笑奈何 提交于 2019-12-17 17:56:17
问题 I'm using simple_form gem for creating Rails forms. http://github.com/plataformatec/simple_form All is great, except how do I create a grouped select box? Can't find it in the docs or by google-ing. 回答1: The question is old but it's the top result for "simple_form grouped select" google search anyway so I figured the next reader might benefit from a few creative ways to create these with the latest simple_form (taken from tests, which are always the best documentation indeed) <%= f.input

Is there a way to pass params when clicking submit button in simple_form view in rails 3.2.12?

淺唱寂寞╮ 提交于 2019-12-17 16:16:00
问题 In simple_form view, the submit button is like this: <%= f.button :submit, 'Save' %> We are trying to pass a params subaction when clicking the Save button. The params[:subaction] should have value of 'update' after clicking the button. Here is what we tried in view but it did not work: <%= f.button :submit, 'Save', :subaction => 'update' %> Is there a way to pass a value in params[:subaction] when clicking the Save button? 回答1: Use name and value option. <%= f.button :submit , name:

rails simple_form fields not related to the model

筅森魡賤 提交于 2019-12-17 15:34:35
问题 I have an existing form which is tied to a model named 'Order', but i want to add new form fields that will capture Credit Card info such as name, cc number, etc to be processed on a 3rd party payment gateway. But since i don't want to save CC info in our database, there are no corresponding columns of that in my order table. And this gives me an error when submitting the form that those Credit card input fields are not 'part' of the order model. 回答1: You can use attr_accessor class Order <

Translating custom error messages

时光毁灭记忆、已成空白 提交于 2019-12-14 04:00:33
问题 I have a form (using simple_form) which I want to implement support for translated error messages. All my translations appear with the exception of the error message. My Customer model is: class Customer < ActiveRecord::Base attr_accessible :name, :phone, :email, :contact_method validates_presence_of :phone, :email, :contact_method, :message => I18n.t(:required) end My fr.yml file fr: name: 'Nom' phone: 'Téléphone' email: 'Courriel' contact_method: 'Méthode de contact' required: 'Requis' My

Simple_form required field does not work - Ruby on Rails

纵饮孤独 提交于 2019-12-14 03:45:32
问题 I have a submiting form in a RoR app, built with simple_form. When the fields are blank, the app still goes to the next step without prompting an error or warning. The fields are supposed to be by default required: true ; but even writing it manually does not work. The app has 3 steps: NewPost (new view) -> Preview (create view) -> Post. It would be more clear with a extract of my controller and views: def new @post= Post.new end def create @post = Post.new(params.require(:post).permit(:title