formtastic

virtual model and form_for (or formtastic)

a 夏天 提交于 2019-12-02 21:20:53
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. 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 argument, and Formtastic will build the form and post the params based on the symbol. Eg: <% semantic_form_for(

Get a value of object field inside fields_for loop

霸气de小男生 提交于 2019-12-02 17:55:23
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 object, so I couldn't get the value of :review_crieteria_id . Formtastic adds additional features to the

Rails4: Formtastic3.0 , save multiple instances (for Answer models) at the same time

狂风中的少年 提交于 2019-12-02 15:13:30
问题 I have Question model and an answer model. Each question can have one answer per user. I am trying to preset to a user a form to answer all questions, but couldnt really figure out how to do it with formtastic Here is what I have so far - @questions.each do |q| = q.content - ans = @user.answers.where(question_id:q.id).first.try(:content) || q.description = semantic_form_for @answers do |f| = f.label q.content = f.inputs :content, placeholder: ans = f.actions I am trying to get some hint from

Rails4: Formtastic3.0 , save multiple instances (for Answer models) at the same time

折月煮酒 提交于 2019-12-02 10:26:21
I have Question model and an answer model. Each question can have one answer per user. I am trying to preset to a user a form to answer all questions, but couldnt really figure out how to do it with formtastic Here is what I have so far - @questions.each do |q| = q.content - ans = @user.answers.where(question_id:q.id).first.try(:content) || q.description = semantic_form_for @answers do |f| = f.label q.content = f.inputs :content, placeholder: ans = f.actions I am trying to get some hint from How to loop through two alternating resources on a form? but I keep getting "undefined method `model

Railscast 198, but using formtastic

谁都会走 提交于 2019-11-30 22:19:31
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. 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 product in @products %> <% f.fields_for "products[]", product do |ff| %> <h2><%=h product.name %></h2> <%=

Formastic Bootstrap Rails Error- No Such File to Load ButtonsHelpers

为君一笑 提交于 2019-11-30 20:27:38
I'm completely stuck on this error. Using Rails 3.1 trying to implement Formastic Bootstrap gem and getting error: `': no such file to load -- formtastic/helpers/buttons_helper (LoadError) Application.css *= require formtastic *= require formtastic-bootstrap Gemfile group :assets do gem 'sass-rails', " ~> 3.1.0" gem 'coffee-rails', "~> 3.1.0" gem 'uglifier' gem 'less-rails-bootstrap' gem 'bootstrap-sass' end formastic.rb Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder gem 'formtastic' gem 'formtastic-bootstrap' buttons_helper module FormtasticBootstrap module Helpers

HTML - Correct way of coding a checkbox with a Label

有些话、适合烂在心里 提交于 2019-11-30 18:08:20
I've been using formtastic in order to generate HTML forms on rails applications. My question, however, is really HTML-related. Today I found a strange behaviour on the way formtastic generates checkboxes (fields of type :boolean on formtastic lingo). The rest of the fields (non-checkboxes) are generated this way: <li> <label for="my_textbox_field">My TextBox</label> <input id="my_textbox_field" type="text" ... > </li> Checkboxes, however, are enclosed inside their <label> tags completely - like this: <li> <label for="my_boolean_field"> <input id="my_boolean_field" type="checkbox" ... > This

formtastic - how to prepopulate a string input with a value

谁说我不能喝 提交于 2019-11-30 12:30:21
问题 I'm building an app, where users can give comments by just leaving their email to the comment. I want them to be able to register directly from there, by a link with their email adress as a param (like: <%= link_to register_path(:email => @comment.email %> ) - so there is no existing user record yet. this should be done by applying a value to the form.input field via the :value option. But the following code doesn't work! <%- if params[:email] -%> <%= f.input :email, :required => true, :value

2 submit buttons in a form

馋奶兔 提交于 2019-11-30 09:20:06
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 would be set to true. If the latter, then false. In PHP, I used to display 2 submit fields with

Activeadmin formtastic dynamic select

Deadly 提交于 2019-11-30 07:15:58
问题 I would like to make a dynamic select option via Activeadmin 's formtastic like so: form do |f| f.inputs "Exam Registration Details" do f.input :user_id, :as => :select, :collection => User.where(:admin => 'false') #selects user from list. WORKING f.input :student_id, :as => :select, :collection => Student.joins(lessons: :user) #collection of students will change to students who have lessons with chosen user. NOT WORKING, returns all students who have lessons. f.input :lesson_id, :as =>