FAQ Database Discussion Community


SimpleForm submit with “return” key

javascript,ruby-on-rails,simple-form
Using the simple_form gem and rails I'm attempting to have a text_area (comment box) submit by only hitting the return key. Facebook has a similar feature and that's what I'm shooting for. Researching online hasn't produced much and I'm fairly new to Javascript still. Any suggestions? Form Partial <%= simple_form_for...

Ruby haml unexpected ending error

ruby-on-rails,ruby,haml,simple-form
= simple_form_for @pin, html: { multipart: true} do |f| - if @pin.errors.any? #errors %h2 = pluralize(@pin.errors.count, "errors") prevented this Pin from saving %ul - @pin.errors.full_messages.each do |msg| %li= msg .form-group = f.input :title, input_html: { class: 'form-control' } .form-group = f.input :description, input_html:{ class: 'form-control' } = f.button :submit, class:...

How to set default value for association with simple_form?

ruby-on-rails,forms,default,simple-form
I'd like to do something like this: <%= f.association :productgroup, default: params[:productgroup_id] %> The params should only be used if there is no value (lets say for new records), so selected: is not what I'm looking for because it overrides the value when I edit the record. Thanks, Andreas...

Undefined method error when using simple_form (newbie)

ruby-on-rails,simple-form
I've got the following simple_form: = simple_form_for instance do |f| = f.input :update_resolution, collection: 1..10 = f.button :submit It throws the error: undefined method `update_resolution' for #<Instance:0x007f0c07329640> In instances_controller.rb I have: def update_resolution render nothing: true, status: 200, content_type: 'text/html' end And I'm not 100% sure what's best to put...

Simple_form path issue

ruby-on-rails,simple-form,rails-routing
Here is what I have in my view: <%= simple_form_for :artist, :url => url_for(:action => 'upvote', :controller => 'artists'), :method => 'post' do |f| %> <%= f.input :choose_an_artist, :selected => "first artist", collection: [["first artist", 1], ["second artist", 2], ["third artist", 3], ["fourth artist", 4]] %> <%= f.submit "Vote" %>...

Display Daylight Saving Time when using simple_form and time-helper

ruby-on-rails,datetime,simple-form
I am trying to create a drop down with different timezones using the simple_form gem and the timezone helper. This works fine using this bit of code: .tag = f.input :timezone, as: :time_zone The problem is, that the timezone is displayed like so GMT+1 even though, thanks to daylight saving...

Rails - Simple Form - style error messages

ruby-on-rails,simple-form
I'm trying to make a partial in my views folder, which his shared for error messages. I want to remove the simple form standard error message and replace it with my own styling - across all models. My question is, how do I reference the relevant model in my partial....

Editing multiple objects with simple_form

ruby-on-rails,simple-form
In the Railscast dealing with Editing Multiple, Ryan shows how to edit multiple objects in batch with form_tag. Is there a good way to do this using simple_form?

Passing parent value to simple form

ruby-on-rails,ruby,simple-form
I have a project and to add a service to the project I pass the project id to the service with: new_service_path(project: "#{@id}") My Services controller then finds the project: def new @service = Service.new @project = Project.find(params[:project]) @service.documents.build end I can display the project in the view but I...

Can't update existing records in Rails app

ruby,ruby-on-rails-4,simple-form
It appears that everything saves properly on my Rails 4 app (using simple_form) when I create a new event, but when I try to update an existing event (by going to events/3/edit), it doesn't save any of the changes. Here is my console log: Started PATCH "/events/3" for 12.43.117.2 at...

Basic User Authentication in Rails

ruby-on-rails,authentication,simple-form
I'm working on implementing some basic user authentication in Rails 4, following this article http://nycda.com/blog/basic-user-authentication-model-in-rails-4/ Instead of using the ERB form provided, I recreated (at least I thought I did) the process with simple_form, and the query being passed when I try and log in is this: SELECT `users`.* FROM...

Display title on checkbox hover over in Ruby

ruby-on-rails,ruby,checkbox,simple-form
I am struggling with what I thought was a simple issue. I want to give a checkbox a title, alt or similar so that when I hover over the checkbox I will be given some specific information. Here is a jsfiddle example for text or a code example below (both...

Association belongs_to vs nested attributes in the form

ruby-on-rails,ruby-on-rails-4,associations,simple-form
I have a situation like below: class User < ActiveRecord::Base belongs_to :user_group accepts_nested_attributes_for :user_group end class UserGroup < ActiveRecord::Base has_many :users end Controller: UsersController < ApplicationControler def new @user = User.new @user.build_user_group end def create @user = User.new(user_params) if @user.save # do something else # do something end end private...

Client side validation in rails? Is there no hope?

jquery,ruby-on-rails,ruby,validation,simple-form
Im using simple_form which im beginning to regret, simply (pun) because of the amount of work around you have to do to get anything done right. Im using the latest verson of rails 4 and everythings going well except for client side validation on all of my forms. I cant...

Persist jQuery On Submission Failure - Rails

jquery,ruby-on-rails,simple-form
In the form I created, when a user selects "Member type" from a dropdown menu, specific div's are displayed in accordance with that member type using jQuery. For example, selecting "Youth Member" will display input fields for "DOB" and "Hour". The problem I've been experiencing is that on a failed...

simple_form_for with localized, scoped routes and Mongoid (missing required keys: [:id])

ruby-on-rails,mongoid,simple-form,rails-i18n
I have a _form.html.haml partial for a model FileType that I want to render in my new.html.haml and edit.html.haml view. = simple_form_for [:document_manager, file_type] do |f| ... When I render this partial in the new view, this works, but when I render it in the edit view, simple_form tries to...

Creating inputs dynamically from a hash with simple form

ruby-on-rails,postgresql,simple-form
I have a Configuration model which stores settings in a JSONB column. # Stores site wide configuration settings # This is used in conjunction with PaperTrail to make each change traceable class Configuration < ActiveRecord::Base has_paper_trail validates_uniqueness_of :name after_initialize :default_values if :new_record? private def default_values self.settings = { site_title: 'Portfolio...

What Is The Best Method To Create Edit Forms?

ruby-on-rails,ruby,twitter-bootstrap,simple-form
I'm working on an application in Ruby on Rails (Ruby 2 - Rails 4 - Bootstrap 3) I have used the simple_form gem to build the forms, like signup and register, but how do you create a form that loads an object from the database and allows a user to...

How do I force simple_form to set the fields of an existing resource to be blank?

ruby-on-rails,ruby-on-rails-4,simple-form
This is my form: <%= simple_form_for resource, :as => resource_name, :url => invitation_path(resource_name), :html => {:method => :post} do |f| %> <%= devise_error_messages2! %> <% resource.class.invite_key_fields.each do |field| -%> <%= f.input :first_name, label: "Family Member's First Name:", input_html: { maxlength: 15, size: 40 } %> <%= f.input :last_name, label: "Family...

Simple Form - Rails 4 - editing

javascript,ruby-on-rails,simple-form
I am trying to use simple form with my rails 4 app. I have a project model, which has a scope model. Scope belongs to project. I have a third model, called participant, which belongs to scope. Scope accepts nested attributes for participant and project accepts nested attributes for scope....

How do I send a local variable to a partial rendered only after a link is clicked?

javascript,ruby-on-rails,twitter-bootstrap,ruby-on-rails-4,simple-form
I have a Bootstrap Modal that is triggered when this link is clicked: <a class="plus" href="javascript:;" data-toggle="modal" data-target="#myModal">&nbsp;</a> I then have this in my _footer.html.erb <%= render 'shared/tag_users_modal' %> Which then has this standard Bootstrap Modal: <!-- Modal --> <div class="modal tagging fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog">...

How to use simple form for comments from a nested resource?

ruby-on-rails,ruby,ruby-on-rails-4,simple-form
So I'm creating a blog rails app and I'm trying to create a comment session on the blog. I'm trying to render a form using simple form, but I'm having a hard time getting the simple form to work. For now I have: <%= simple_form_for ([@user, @post.comments.build]) do |f| %>...

f.input rows not working Rails 4

ruby-on-rails,ruby-on-rails-4,rows,simple-form,formbuilder
Using simple form and f.input on my rails 4 app, however, the row amount is not working. Displays 1 row only. <%= simple_form_for(@article) do |f| %> <%= f.error_notification %> <%= f.input :whyrating, :input_html => { :rows => 5 } %> <% end %> also tried without input_html <%= f.input :whyrating,...

simple_form - can't generate combined select input

ruby,simple-form
I have complex form with a lot of controls, and I'm currently using simple_form gem due to its flexibility. But when I wanted to do something more complex I faced to several problems that currently looking obscure for me. I would like to introduce combined collection input, that will render...

Adding space between labels and fields

ruby-on-rails-4,twitter-bootstrap-3,devise,simple-form
In my Rails app, the labels for the fields on the login page are way too close to the fields themselves, making it look cramped. I want to add space between them, but am not sure how. I have Rails 4 with simple_form, bootstrap 3, and devise installed. This is...

Trying to call this method in my view and pass the input to the method argument

ruby-on-rails,ruby,methods,view,simple-form
Here is my method in my user controller: def donation_custom(amount) @user = current_user @user.amount_donated += amount @user.save redirect_to root_path, :alert => "thanks for donating" end I just need a simple input form in my view so i can call this method and pass the user input to my "amount" argument....

How to add sr-only class to input's label?

ruby-on-rails,twitter-bootstrap-3,simple-form
I have simple form: <%= simple_form_for @link do |f| %> <%= f.input :url, placeholder: "http://..." %> <%= f.button :submit, "Submit Link", class: "btn-primary" %> <% end %> it outputs input like this: <div class="form-group url required link_url"> <label class="url required control-label" for="link_url"> <abbr title="required">*</abbr> Url </label> <input class="string url required...

Rails 4 Attempting to save Multiple Records to single Model

ruby-on-rails-4,rails-activerecord,simple-form,omnicontacts-gem
I am using the Omnicontacts Gem to pull a list of contacts. So far that works. I can get the contacts and use them to populate a form so I can pass them to my Contacts Controller to be saved in the Contact Model. I have looked at the Rails...

Bootstrap “multiple” attribute for simple_form

html,ruby-on-rails,twitter-bootstrap,simple-form
I would like to have a scroll down menu with different options to choose from using Bootstrap, as demonstrated here: <select multiple class="form-control"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> I am currently using simple_form to construct my menu (it is a dropdown menu by default): <%= f.input :member_type, collection: Form::MEMBERSHIPS,...

html rows mis-aligned with simple_form 2.1.2 and bootstrap 3/Rails 3.2

html,ruby-on-rails-3,twitter-bootstrap,simple-form,simple-form-for
Here is a html page rendered through simple_form 2.1.2 with 3 mis-aligned rows on bootstrap 3 and rails 3.2. We know that bootstrap 3 is not compatible with simple_form 2.1 and rails 3.2. The html source code of all rows have the same structure (difference name of course). Also we...

simple_form custom inline_checkbox markup

html,ruby-on-rails,ruby,simple-form
I'm trying to change the markup of an label_input. This line (from simple_form_bootstrap.rb, wrapper inline_checkbox) ba.use :label_input, :wrap_with => { :class => 'checkbox inline' } and the call from my template: = f.input :my_checkbox, as: :boolean, wrapper: :inline_checkbox, label: false, inline_label: "My label" I get the following markup: <div class="control-group...

Rails 4:Simple-form checkbox for active and inactive post

ruby-on-rails,ruby-on-rails-4,checkbox,haml,simple-form
Have created a check box -Boolean function in Simple-form, wanted to know how the controller can hide the post when indicative from index. When a user creates a post he has an option to hide the post from all the post list (index.html.haml). In the form i have created active...

Rails: Simple Form Custom Label Not Working

ruby-on-rails,ruby-on-rails-4,simple-form
I'd like to create a custom label for a simple form field. For some reason, the below code isn't creating that label. It's still using the default label. I must be missing something easy. Simple Form 3.1 <%= simple_form_for "#" do |f| %> <%= f.input :street, label: "Custom Label" %>...

Only showing inputs for attributes that are not readonly on update

ruby-on-rails,ruby-on-rails-4,simple-form
I have a model Foo with attributes bar and baz. Baz is marked as attr_readonly as it's value cannot be changed after it has been created. Is there a way to not display the baz input field in the partial firm rendered? This should be dynamic as this firm is...

Rails simple_form text_area doesn't display errors

ruby-on-rails,ruby,validation,ruby-on-rails-4,simple-form
I have a Rails form created with simple_form like so: = simple_form_for @new_biz, url: new_business_post_path, html: {:class => "customForm1", :method => "post"} do |f| = f.input :business_name, label: false, :input_html => {:value => @wat.business_name, :readonly => true} = f.input :wat_id, :as => :hidden, :input_html => {:value => @wat.id} = f.input...

When I click submit button in my form, create action is supposed to work but it is rather processed by new action

ruby-on-rails,simple-form,simple-form-for
In my application, I have a form that is supposed to be processed by create action but it is rather processed by new action. This problem is happening in my post task form, but in my other form (registration form), it is working very well (it is processed by create...

Rails, Simple Form, Nested Forms

ruby-on-rails,simple-form
class Project has_many :project_questions, dependent: :destroy#, through: :projects accepts_nested_attributes_for :project_questions end I am trying to make an app with rails 4 and Simple Form. I have models called projects, project_questions and project_answers. The associations between them are: Projects: has_many :project_questions, dependent: :destroy#, through: :projects accepts_nested_attributes_for :project_questions Project questions: belongs_to :project#,...

Rails 4 render simple-form NEW in INDEX

ruby-on-rails,forms,ruby-on-rails-4,activerecord,simple-form
While trying to render out simple_form new in index.I have followed http://guides.rubyonrails.org/v2.3.11/layouts_and_rendering.html ,,in that 2.2.2 Rendering an Action’s View and i am getting error NoMethodError in Posts#index ,undefined method `model_name' for NilClass:Class class PostsController < ApplicationController before_action :find_post, only: [:show, :edit, :update, :destroy] before_action :authenticate_user!,except:[:index,:show] def index @posts = Post.all.order("created_at...

remote form only if user isn't signed in Rails 4

ruby-on-rails,ruby-on-rails-4,simple-form
I just want unsigned-in users to use the form with remote: true but at the same time signed_in users should be redirected normally. So I tried something like this but it isn't working (doesn't even seem right) but you get the idea: <%= simple_form_for(@post, html: {class: "form-horizontal"}) if user_signed_in? do...

simple_form date input not showing in same line

ruby-on-rails,twitter-bootstrap,ruby-on-rails-4,simple-form
i have an input date in my form: <%= simple_form_for @user, url:wizard_path, html: {class: 'form-horizontal'}, wrapper: :horizontal_input_group do |f| %> <%= f.simple_fields_for :educations do |b| %> <%= b.input :school_name %> <%= b.input :degree %> <%= b.input :year_started %> <%= b.input :year_finished %> <% end %> <%= f.button :submit, "Continue" %>...

Two Association Label Elements in Simple Form

ruby-on-rails,ruby-on-rails-4,associations,simple-form
How can I add two label elements when choosing association in Simple Form on Ruby on Rails? Sample: @user.name = "Barack" and @user.last_name = "Obama" Here is my code: <%= f.association :persona, :collection => Persona.order(:name), :prompt => 'Choose a person' %> It displays only Barack but I need it to...

Styling checkboxes rails

ruby-on-rails,ruby,simple-form
I'm trying to style checkboxes in my rails app. <div class="form-group"> <%= f.label :tag_list %> <p>Science</p> <%= f.check_box :tag_list, { :multiple => true }, 'science', nil %> <p>Math</p> <%= f.check_box :tag_list, { :multiple => true }, 'math', nil %> </div> In my application.js //= require jquery //= require jquery.turbolinks //=...

simple_form inline on rails 4

ruby-on-rails-4,simple-form,simple-form-for
I am using a simple_form and bootstrap in rails 4. I want the start date and start time to be on the same line and end date and end time on the same line. I have tried the solutions from similar problems but none of them are working. I am...

Contact form not displaying on the page

html,ruby-on-rails,simple-form
Hey I am trying to create a contact page for my rails app. I created a contact model: class Contact < ActiveRecord::Base end a contact controller: class ContactsController < ApplicationController skip_after_action :verify_authorized def new @contact = Contact.new end def create end end ran a migration : class CreateContacts < ActiveRecord::Migration...

Simple Form - filtering updated attributes in the log

ruby-on-rails,forms,simple-form,patch,update-attributes
Simple question about Simple Form: I've an attribute in a user model for a token I'd like marked as [FILTERED] when passed over the network (as the password field does by default). e.g. I have: Parameters: { "token"=>"WYXe3Z24JmUq", "email"=>"[email protected]", "password"=>"[FILTERED]"}} I want: Parameters: { "token"=>"[FILTERED]", "email"=>"[email protected]", "password"=>"[FILTERED]"}} and an example...

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

ruby-on-rails,ruby-on-rails-4,simple-form
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?...

Hide label in certain resolution with simple_form

ruby-on-rails-3,twitter-bootstrap,simple-form
I have this wrapper in simple_forms config.wrappers :styled_horizontal_boolean3, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| b.use :html5 b.optional :readonly b.use :label, class: 'hidden-sm hidden-xs col-md-3 control-label' b.wrapper tag: 'div', class: 'col-md-9 checkbox-margin' do |wr| wr.wrapper tag: 'div', class: 'styled checkbox' do |ba| ba.use :label_span_input, class: 'col-md-9', span_class: 'left' end...

how to add text in label tag simple_form

ruby-on-rails,simple-form
I'm using simple_form and trying to add text before the closing label tag. <label>search</label> This is what I have <%= simple_form_for "", html: { id: "searchform1", class: "searchform", role: "search" }, :method => :get do |f| %> <%= f.input "", wrapper: false, label_html: { id: "spanLabel0", class: "fLabel"}, input_html: {size:...

Rails simple_form - Nested Form NoMethodError in “show” page

ruby-on-rails,simple-form,nested-forms
Im having some difficulty with making a nested form to work using simple_form, specifically with the show page. I have a Profile and Experience model, and would like to nest the Experience model within the Profile model. I believe I have set up the form file and controller and associations...

nested model attributes + wicked wizard form not working

ruby-on-rails-4,simple-form,nested-attributes,wicked-gem
I am making an app based on the railscast tutorial 346(Wicked gem) and 196(nested model). I am trying to combine these 2 together and I am stuck because strong param attributes are not saving. So my app goes like this: I have a user, work, and education model. user.rb: has_many...

Rails 4 Carrierwave, simple_form does not invoke ActionDispatch when hidden field used

ruby-on-rails,ruby-on-rails-4,carrierwave,simple-form
The goal: User selects either a avatar image for upload and clicks "Upload" or clicks "Reset" to remove the custom avatar image and use default. (The underlying forms, controller, action, model are the same except for the "picture" field is hidden in the non-working form.) 1- When the user selects...

How do I update a simple_form input field using AJAX?

jquery,ruby-on-rails,ajax,simple-form,nested-set-model
I have a simple_form input field that is part of a form that I need to update asynchronously when the onchange event is triggered. The field that I need to update is displayed as a select box since it is a collection. But the collection represents records of a nested...

Rails - Simple Form - Nested Resources paths

ruby-on-rails,simple-form,simple-form-for
I am trying to make an app in Rails 4 using simple form. I have 3 models: Project, Project_Question, Project_Answer The associations are: Project: has_many :project_questions, dependent: :destroy#, through: :projects accepts_nested_attributes_for :project_questions Project Question: belongs_to :project#, counter_cache: true has_one :project_answer, dependent: :destroy belongs_to :user accepts_nested_attributes_for :project_answer Project Answer: belongs_to :project_question#,...