simple-form

How to create horizontal forms with twitter bootstrap and rails simple form

烂漫一生 提交于 2021-02-20 18:51:26
问题 I am trying to create horizontal forms with simple-form and bootstrap. I have already installed bootstrap using "rails generate simple_form:install". This is what i have in html.erb <%= simple_form_for(@company, :html => { :class => "form-horizontal" }) do |f| %> <div class="form-group"> <label class="col-md-4 control-label"></label> <div class="col-md-4"> <%= f.input :name %> </div> </div> But the form still appears vertically. 回答1: simple_form is a really great gem for generating bootstrap

How to create horizontal forms with twitter bootstrap and rails simple form

☆樱花仙子☆ 提交于 2021-02-20 18:49:21
问题 I am trying to create horizontal forms with simple-form and bootstrap. I have already installed bootstrap using "rails generate simple_form:install". This is what i have in html.erb <%= simple_form_for(@company, :html => { :class => "form-horizontal" }) do |f| %> <div class="form-group"> <label class="col-md-4 control-label"></label> <div class="col-md-4"> <%= f.input :name %> </div> </div> But the form still appears vertically. 回答1: simple_form is a really great gem for generating bootstrap

How to set simple_form input default value

怎甘沉沦 提交于 2021-02-18 19:16:12
问题 = r.input :date_start do = r.text_field :date_start, id: 'date_start' How can I set default value for this? 回答1: = r.input :date_start, as: :string, input_html: {value: '01/01/2015', id: 'date_start'} 回答2: use this code: = r.input :date_start, as: :string, input_html: {id: 'date_start',value: '07/02/2015'} 回答3: Use of Safe Navigation or &. explained in this Answer to another question, is an option here; especially when chained with the || operator. Looking at the Answer from Kiry Meas Note: I

How to set simple_form input default value

柔情痞子 提交于 2021-02-18 19:15:29
问题 = r.input :date_start do = r.text_field :date_start, id: 'date_start' How can I set default value for this? 回答1: = r.input :date_start, as: :string, input_html: {value: '01/01/2015', id: 'date_start'} 回答2: use this code: = r.input :date_start, as: :string, input_html: {id: 'date_start',value: '07/02/2015'} 回答3: Use of Safe Navigation or &. explained in this Answer to another question, is an option here; especially when chained with the || operator. Looking at the Answer from Kiry Meas Note: I

simple form multiple forms for same resource type on page

◇◆丶佛笑我妖孽 提交于 2021-02-11 07:29:57
问题 I'm using simple_form to create forms for same resource types, it works fine but I've one problem with the javascript due to the fact that all inputs have the same id. For example, if my model is car and my field is brand, all the inputs for this field on al lteh forms have the same id car_brand . Is there a way to add a prefix to the id generated by simple_form inputs Without adding id to each input 回答1: Pass your each form declaration a namespace attribute like below to create uniqness. <%=

how to remove asterisk in required fields when using simple form?

泪湿孤枕 提交于 2021-02-10 16:47:47
问题 In the simple_form initializer there is this line # How the label text should be generated altogether with the required text. # config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" } I removed the comment and changed it to # How the label text should be generated altogether with the required text. config.label_text = lambda { |label, required, explicit_label| "#{label}" } But this doesnt affect the asterisk in the required fields. The * is still present in the

Inserting checkbox array into database

谁说我不能喝 提交于 2021-02-05 07:57:05
问题 I am stuck in that although my array parameter is being captured, it fails to insert it into the database. I do not get an unpermitted parameters error or anything. It just fails to recognize the array when inserting to the DB. What I would like to do: Capture any box that is checked off, and insert the data as separate rows into the database. Here is what I have: /subscribe/categories/2 <div> <%= simple_form_for @subscription do |f| %> <div class="form-inputs"> <%= f.hidden_field :dashboard

Rails Simple Form input with Font-Awesome

我的梦境 提交于 2021-01-29 08:17:06
问题 I want to use icons instead of text for labels in a horizontal simple_form. However, I am unable to separate the text from the icons = simple_form_for @user, html: { class: 'form-horizontal' }, wrapper: :horizontal_form do |f| # shows 'username' label only = f.input :username # shows icon with 'username' = f.input :username, label_html: {class: "fas fa-user"} # shows nothing = f.input :username, label_html: {class: "fas fa-user"}, label: false 回答1: You can use the wrapper_html option: = f

Simple_form_for action hitting wrong URL on edit in rails

泪湿孤枕 提交于 2021-01-29 07:18:39
问题 I have created a simple_form_For common for both new and update, currently, it's working fine for new but for edit/update, it calling the wrong URL. class NewsfeedsController < ApplicationController before_action :find_post, only: [:show, :destroy, :edit, :update] def index @posts = Post.all.order("created_at DESC") end def show # before_action is taking care of all 4 i.e(sho,edit,update and destroy)..Keeping it DRY end def new @post = Post.new end def create @post = Post.new(post_params) if

Ruby on Rails - Simple Form autocomplete association search

和自甴很熟 提交于 2021-01-27 07:35:40
问题 I've a form in a basic task management app which allows Tasks to be assigned to Users (task belongs_to user). I'm using Simple Form for this. Currently, the association is populated in the typical manner, with a dropdown list of users as such: <%= f.association :user, label_method: :name, value_method: :id, include_blank: false %> . However, as the number of Users grows, I'm looking to change this to an autocomplete form field to find users. I've tried following the Railscast on the subject,