formtastic

ActiveAdmin with has_many problem; undefined method 'new_record?'

喜夏-厌秋 提交于 2019-11-28 20:44:31
问题 I'm trying to customise a ActiveAdmin form for a Recipe model that has a has_many relationship with Step. class Recipe < ActiveRecord::Base has_many :steps end class Step < ActiveRecord::Base acts_as_list :scope => :recipe belongs_to :recipe end I have the following in my ActiveAdmin file with relation to this: form do |f| f.has_many :steps do |ing_f| ing_f.inputs end end The following error is thrown when I try to load the form: undefined method `new_record?' for nil:NilClass I've isolated

rails ActiveAdmin nested form has_one accepts_attributes_for formtastic issue

僤鯓⒐⒋嵵緔 提交于 2019-11-28 19:16:43
I am using ActiveAdmin and Rails 3.1 -- having problem understanding whether the following is a bug, or if there is some way to do it correctly that I am not understanding. I am trying to use a nested model with a has one relationship, so that I can create a page and fill out it's meta data in 1 step. -- (page has_one meta_data, accepts_nested_attributes_for meta_data) Example 1) in this example, when I click new page, meta data section is there but there are no input fields -- also, if I edit the record, it shows up correctly, however the fieldset is duplicated in the second section... and if

Insert a non-input row into a Formtasic form

倾然丶 夕夏残阳落幕 提交于 2019-11-28 18:52:44
I am using Formtastic 2.1.1 in Rails 3.2 (with Active Admin) and I want to insert a row into my form that does not have an input field present. Is this possible and what is the syntax in the Formtastic DSL to achieve this? Here's an example: form do |f| f.inputs "Model Info" do f.input :title f.input :published f.input :path end end I'd like to do something like this: form do |f| f.inputs "Model Info" do f.input :title f.input :published f.input :path f.div "This is some important text that people using this form need to know" end end Has anyone done this with Formtastic before? To insert any

Rails 3, nested multi-level forms and has_many through

北战南征 提交于 2019-11-28 17:07:24
I'm trying to get it to work but it dosen't! I have class User < ActiveRecord::Base has_many :events, :through => :event_users has_many :event_users accepts_nested_attributes_for :event_users end class Event < ActiveRecord::Base has_many :event_users has_many :users, :through => :event_users accepts_nested_attributes_for :users end class EventUser < ActiveRecord::Base set_table_name :events_users belongs_to :event belongs_to :user accepts_nested_attributes_for :events accepts_nested_attributes_for :users end And also the table-layout event_users user_id event_id user_type events id name users

Multi-step form in Rails 3 with Paperclip attachments

房东的猫 提交于 2019-11-28 07:36:45
问题 I'm creating a multi-part form in the style that Ryan Bates describes here: http://railscasts.com/episodes/217-multistep-forms http://asciicasts.com/episodes/217-multistep-forms (text-based version) To summarize, I have one view (with a bunch of partials for each form step), and the form variables are stored in a session when the user clicks a next button and a different part of the form is displayed. One of my form steps allows the user to upload several images via the Paperclip gem. The

Include two inputs in same LI element in Formtastic

不羁的心 提交于 2019-11-28 04:18:21
问题 Using formtastic, I have a quantity field and unit field that asks for the quantity of the item and the unit it's measured in. My problem, is that I would like the unit box to display along side the quantity box. However, because formtastic pust each input in it's own LI element, I can't get them to appear next to each other. Any ideas? 回答1: Use an html wrapper for your quantity and unit fields: <%= form.input :quantity, :wrapper_html => { :class => 'fl' } %> <%= form.input :unit, :wrapper

how to embed raw html in active_admin formtastic

左心房为你撑大大i 提交于 2019-11-28 01:46:51
问题 I'm trying to build a form, with formtastic, inside an active_admin model. The problem is I need a certain script tag and other raw HTML stuff directly inside or around the form. I'm doing it with the normal form block: form do |f| f.inputs :name => "User Details", :for => :user do |user_form| user_form.input :first_name, :required => true ... How do I embed a simple div tag right in between? Or even a script tag? I thought about using a render :partial , but I want to know if the above

Rails Formtastic: adding “data-” field to option tag

喜欢而已 提交于 2019-11-28 00:43:28
I have: form.input :duration, as: select, collection: {} I need: <option value="" data-price="XXX"></option> Rails does not support HTML5 data attributes for the option tag. Formtastic suggests to create a helper method for this. Formtastic readme describes how to extend input tags. However, in select_input.rb I can't find any method which would affect the option tag. So, how do I do this? Also, I found enhanced_select gem which does exactly what I need, but I am not able to make it work with formtastic. Actually rails does support adding any kind of html tag to options. Usually you would have

how to change class of a label for checkboxes in simple_form

青春壹個敷衍的年華 提交于 2019-11-27 20:52:21
问题 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? 回答1: 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

Nested form in activeadmin not saving updates

瘦欲@ 提交于 2019-11-27 14:00:36
问题 I have a nested form in ActiveAdmin for these models (a :class_section has_many :class_dates): class ClassDate < ActiveRecord::Base belongs_to :class_section validates :start_time, :presence => true validates :end_time, :presence => true end and class ClassSection < ActiveRecord::Base belongs_to :class_course has_many :class_dates belongs_to :location accepts_nested_attributes_for :class_dates end Everything seems to be in the right place when I look at the form. However, when I update a