formtastic

Accessing object of form in formtastic

自闭症网瘾萝莉.ら 提交于 2019-12-04 01:13:53
So I'm making a survey app. The users choose a type of form on the backend, and it displays as a certain type on the front end. That's only ideally, of course. What happens now is I can't access the object formtastic is building the form for. How can I say something like "question.kind"? It just makes an error that way. Here's what I have so far... = semantic_form_for @survey, :url => "#", :html => { :method => "get" } do |f| - for question in @survey.questions = user_facing_question(f) and the complementary helper method goes like this so far: def user_facing_question(f) f.inputs end You can

Railscast 198, but using formtastic

删除回忆录丶 提交于 2019-12-03 21:19:51
问题 How could you do what's covered in RyanB's Railscast on editing multiple records individually, using Formtastic? Formtastic doesn't use form_tag, which RyanB's method relies on. 回答1: The semantic_form_for is just a wrapper around form_for so you can use the same parameters. Here is a formtastic version of Ryan Bates' screencast views/products/edit_individual.html.erb <% semantic_form_for :update_individual_products, :url => update_individual_products_path, :method => :put do |f| %> <% for

2 submit buttons in a form

流过昼夜 提交于 2019-12-03 19:36:28
问题 I have a question about forms. I have a fairly standard form that saves a post (called an eReport in my app) with a title and body. The table also has a "published" field, which is boolean. The saved eReport only shows on the public site if this field is set to true, with false being the default. Rather than the default check box, I would like to display two buttons at the end of the form: a "Publish Now" button and a "Save as Draft" button. If the user presses the former, the published field

How does the HTML5 multiple file upload field map to a nested model in Rails 3?

被刻印的时光 ゝ 提交于 2019-12-03 16:14:38
问题 I'm trying to use the HTML5 multiple attribute on a file field in a nested form. The models are as follows: class Album < ActiveRecord::Base has_many :album_images has_many :images, :through => :album_images accepts_nested_attributes_for :images end class Image < ActiveRecord::Base has_many :album_images has_many :albums, :through => :album_images mount_uploader :filename, ImageUploader validates_presence_of :filename end The view: <%= semantic_form_for @album, :url => upload_path do |f| %> <

virtual model and form_for (or formtastic)

醉酒当歌 提交于 2019-12-03 07:52:45
问题 Sometimes we need form without model creation - for example search field or email, where should be send some instructions. What is the best way to create this forms? Can i create virtual model or something like this? I'd like to use formtastic, but not form_tag. 回答1: Firstly, Formtastic doesn't need a model in all cases, although it certainly works best and requires less code with a model. Just like Rails' own built-in form_for , you can pass in a symbol instead of an object as the first

ActiveAdmin - Using scopes with filters

你离开我真会死。 提交于 2019-12-03 07:11:36
In my ActiveAdmin model I have a custom scope to show deleted records and several filters for searching records by specific columns. Using the filters individually or combined together works as expected. Using a scope works as expected. The problem is that using a scope seemingly overrides all the filters and after selecting a scope any filter added does nothing. Anyone have any ideas here? What I want is to be able to show a specific scope and then still be able to filter results within that scope. ActiveAdmin.register Example do scope :deleted do |example| Example.only_deleted end scope :all

How to filter IS NULL in ActiveAdmin?

限于喜欢 提交于 2019-12-03 07:03:23
问题 I've a table with an integer column called "map_id", I want to add an activeadmin filter to filter if this column IS NULL or IS NOT NULL. How could this be implemented ? I tried the following filter filter :map_id, :label => 'Assigned', :as => :select, :collection => {:true => nil, :false => ''} But, I get the following error message : undefined method `map_eq' for # 回答1: Not found a good solution but here is a how. filters of Active_admin are accomplished by meta_search, you can override the

Get a value of object field inside fields_for loop

寵の児 提交于 2019-12-03 05:33:55
问题 In the following scenario, I need to check the value of the object property in the fields_for loop. <%= f.semantic_fields_for :review_details do |rd| %> <%= rd.input :review_criteria_id, :as=>:hidden %> <% end %> As in the loop, :review_criteria_id is rendered as hidden field, but I have a scenario, where I have to print some more information if it is a specific criteria. How can I get the value of review_criteria_id in the loop. I used: rd.review_criteria_id But since rd is the formtastic

How to pre-check checkboxes in formtastic

旧城冷巷雨未停 提交于 2019-12-02 22:51:43
I have a form I'm trying to set up ... Users can have many posts, and each post can have many people watching it. The Watch model is set up polymorphically as 'watchable' so it can apply to different types of models. It has a user_id, watchable_id, watchable_type and timestamps as attributes/fields. This is soley so that when people comment on a post, users watching the post can get an email about it. What I'm trying to do is show the user a list of users that they can tag on each post, which is not problem. This is what I'm using right now http://pastie.org/940421 <% semantic_form_for @update

How to filter IS NULL in ActiveAdmin?

亡梦爱人 提交于 2019-12-02 21:42:38
I've a table with an integer column called "map_id", I want to add an activeadmin filter to filter if this column IS NULL or IS NOT NULL. How could this be implemented ? I tried the following filter filter :map_id, :label => 'Assigned', :as => :select, :collection => {:true => nil, :false => ''} But, I get the following error message : undefined method `map_eq' for # Not found a good solution but here is a how. filters of Active_admin are accomplished by meta_search, you can override the functions automatically generated by meta_search in your model to get the behavior that you want, the best