simple-form

nested attributes in simple_form returns mass assignment error

隐身守侯 提交于 2019-12-04 15:27:04
Models: class Topic < ActiveRecord::Base has_many :posts, :dependent => :destroy validates :name, :presence => true, :length => { :maximum => 32 } attr_accessible :name, :post_id end class Post < ActiveRecord::Base belongs_to :topic, :touch => true has_many :comments, :dependent => :destroy accepts_nested_attributes_for :topic attr_accessible :name, :title, :content, :topic, :topic_attributes end View: <%= simple_form_for :post, :url => { :controller => :posts, :action => "create" } do |f| %> <h1>Create a Post</h1> <%= f.input :name, :label => false, :placeholder => "Name" %> <%= f.input

Numeric field Simple_form_for

依然范特西╮ 提交于 2019-12-04 13:14:25
问题 In my numeric fields when using Simple_form_for, scroll bars are showed on the side of the fields when using Google Chrome. How can I stop them from showing? 回答1: Seeing some code would be helpful , but They're not scrollbars; they're up and down arrow buttons to increment/decrement the number input field the specified step (defaults to 1 ). Learn more about the number input type An integer attribute for your model by default will be rendered with type="number" as a field using simple_form.

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

主宰稳场 提交于 2019-12-04 10:38:24
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 form, Subjects and Categories are interchangeable, but that's not the case elsewhere.) Ideally, this

simple_form with Bootstrap check box

时间秒杀一切 提交于 2019-12-04 09:57:51
问题 I'm using simple_form with Bootstrap and I would like to have my "Remember me" check box be inline to the left of the label, as in the Twitter Bootstrap docs: http://twitter.github.com/bootstrap/base-css.html#forms My form code looks like this: <%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => { :class => 'well'}) do |f| %> <%= f.input :email %> <%= f.input :password %> <%= f.input :remember_me, :as => :boolean if devise_mapping.rememberable? %>

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

断了今生、忘了曾经 提交于 2019-12-04 09:15:38
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? You should specify html5 option: f.input :start_date, as: :date, html5: true Here is details. 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 believe browsers are not totally ready for these yet, but you can easily opt-in on a per-input basis by passing

Simple_Form Association with has_many :through extra field

六月ゝ 毕业季﹏ 提交于 2019-12-04 08:30:43
问题 I have two models, Developers and Tasks, class Developer < ActiveRecord::Base attr_accessible :address, :comment, :email, :name, :nit, :phone, :web has_many :assignments has_many :tasks, :through => :assignments end class Task < ActiveRecord::Base attr_accessible :description, :name, :sprint_id, :developer_ids has_many :assignments has_many :developers, :through => :assignments end class Assignment < ActiveRecord::Base attr_accessible :accomplished_time, :developer_id, :estimated_time,

SimpleForm+ClientSideValidations+bootstrap - Validation is not occuring on the form- all inputs are accepted

心不动则不痛 提交于 2019-12-04 04:23:30
I am using the SimpleForm, ClientSideValidations, and ClientSideValidations-SimpleForm gems in a RoR application. I can render the form into the modal beautifully, however when the input loses focus no validation occurs and the form is submitted. Also note that I have tried using the fix found here: http://www.ddarrensmith.com/blog/2012/05/17/ruby-on-rails-client-side-validation-with-validation-helpers-and-twitter-bootstrap/ Segment of the view containing the form: <div class='modal hide' id='New_Discrep' tabindex="-1" role='dialog' aria-labelledby="#New_Discrep_Label" aria-hidden='true'> <div

Converting String to Date before save with Rails

左心房为你撑大大i 提交于 2019-12-04 02:48:36
Very new to Ruby and I've been stuck for hours. Searching everywhere and can't find an answer. So I'm using the bootstrap datepicker for rails gem. Because I've changed the date format of the datepicker, it won't store in the DB. Guessing this is because the simple_form input is being used as a string to avoid the default date selection inputs applied by simple_form. My question is: How do I modify/convert a string like "06/18/2013" to a date before it is saved to the db? Is this best handled by the controller? My controller: # PUT /events/1 # PUT /events/1.json def update @event = Event.find

Min value for input in Simple Form

半世苍凉 提交于 2019-12-03 23:19:03
I want to create a simple money input with SImpleForm . So the money field should have a minimum value which is 0, so that user cannot enter value less than 0. However I don't know how to define min value with simple form. I wonder if it's possible. Ryan Erdmann Definitely! The (simplified) HTML for the form you want looks something like this: <form> <input type="number" min="0" step="any" name="amount"> </form> Notice the two really important properties on the input field: min is set to 0, because you don't allow negative numbers, and step is set to any , because you want to allow decimals in

can't change the height of a text field in simple_form

时光总嘲笑我的痴心妄想 提交于 2019-12-03 23:07:41
I've tried #Default size for text inputs. config.default_input_size = 10 from config/initializers/simple_form.rb I've also tried <%= f.input :message, :input_html => {:size => 10} %> But neither of these change a single thing about how my text fields appear. You need to do this <%= f.input :message, :input_html => {:rows => 10} %> Html text area tag attributes has two attributes namely rows and cols which lets you specify the no of rows and columns(i.e. width) of your text area. If this is not working then open the console and see if your css is overriding the height. Passing :input_html