Autosize-rails not working - ruby-on-rails

I am trying to use the autosize-rails gem to create text boxes that automatically get bigger when filled. I installed the gem and bundled it.
gem 'autosize-rails
I then added this to my js.coffeescript file:
$(document).ready ->
$("textarea").autosize()
and finally my form looks like this:
<%= f.input :title, as: :text, input_html: { :class => "textarea" }%>
The forms still use the default scroll bar.

I have no experience with this gem, but it looks like you need to change $("textarea") to $(".textarea") in your coffeescript file.

Related

activeadmin adding datepicker

I'm working with rails' activeadmin and creating a custom form like so:
<%= semantic_form_for [:admin, Client.find(#wedding_cake.client_id), #wedding_cake] do |f| %>
than I want to add an input for a date like so:
<%= f.input :date, as: :datepicker %>
However, I'm getting "Unable to find input class for datepicker" from rails.
I've tried including jquery date picker in my gem file, but that didn't change anything. What am I doing wrong?
I ran into this exact issue and what worked for me was: https://github.com/activeadmin/activeadmin/wiki/Combine-datetime-picker-with-activeadmin#or-do-it-manually
Specifically:
In active_admin, change the column use
:as => datepicker TO :as => :string, :input_html => {:class => "hasDatetimePicker"}
However, I had to prepend the datepicker class, and in my case, change hasDatetimePicker to hasDatePicker
:as => :string, :input_html => {:class => 'datepicker hasDatePicker'}
h/t to Eugen's comment for pointing me in the right direction
Try the DateNTimePickerActiveAdmin Rubygem. It works really well and is customisable according to your project.
You can find the documentation here: https://github.com/NikhithaGraceJosh/date_n_time_picker_activeadmin
From the docs:
Gemfile
gem 'date_n_time_picker_activeadmin'
Code Sample (In your form)
f.input :column_name, as: :datetimepicker
CSS
In active_admin.scss, add the line,
#import date_n_time_picker_activeadmin
JS
In active_admin.js, add the line,
//= require date_n_time_picker_activeadmin
Hope it's useful!

Client side validation with judge not working

I am trying to use client side validation with Judge gem but validation not working.
In my gem file I used
# Forms
gem 'simple_form', '3.0.2'
#Client side validations
gem 'judge'
I have simlpe_form gem and I know i need to use plugin for simple form with judge but i am trying to use in normal form_for but its not working with that either.
My model looks like
class User < ActiveRecord::Base
paginates_per 10
validates :name , presence: true, length: { maximum: 200 }
In my view
- title 'User Registration'
.vcentered
.signup-box
- if #user.authorizations.any?
%h1 We just need a little more information...
- else
%h1 We just need a little bit of information...
= form_for #user,:builder => Judge::FormBuilder, url: user_registration_path, html: { class: 'new-user form-default' } do |f|
- if #user.name.blank?
= f.text_field :name, class: class_with_errors(#user, :name),
title: title_with_errors(#user, :name),
placeholder: 'Full Name',
:validate => true
I have followed all configuration stps as given on github page of gem.
Please suggest solution of the problem or how I can find the cause of problem.
in client side validation when i load the page browser is saying (at top middle, I forget what it is called)
The page at localhost: 3000 says: PAge can't be blank. Any idea why it is working like this ?
rails generate judge:install path/to/your/js/dir
and then in your route.rb
mount Judge::Engine => '/judge'

How do I get simple_form and bootstrap to work together?

I'm using simple_form to generate my forms in my Rails application. I'm wanting to use bootstrap with these forms. So I've installed the following gems and added them to my gemfile... (1)simple_form, (2)twitter-bootstrap-rails. Finally, per instructions on the simple_form git page I ran, rails generate simple_form:install --bootstrap.
After running bundle install everything is installed and the server runs. The forms however are still not displaying correctly as they would with the class "form-control".
Form
= simple_form_for #user, html: { multipart: :true, class: "form-horizontal" } do |f|
= f.input :headshot_image, as: :file
= f.input :remote_headshot_image_url, placeholder: "Image Url"
= f.input :first_name, required: true
= f.input :middle_name
= f.input :last_name, required: true
I am able to get it to "work" by two different methods (neither of which I believe are correct). First I can add , class: "form-control" to each input, or I can add to the simple_form_for :defaults => { :input_html => { :class => "form-control" } }. The former which kinda defeats the purpose I believe, and the latter works, but it also applies the class to the file input which is not ideal.
Is there a setup step that I missed? Or have I done something incorrect. If I need to provide more information or left something out please let me know. Thanks!
Probably you forgot about adding bootstrap assets to application.css file
simple_form Readme has following line:
You have to be sure that you added a copy of the Bootstrap assets on your application.

Ruby on Rails looking for value from key in devise gem

I'm new to ruby on rails, and I installed devise on my application. I was wondering where I can customize the values if a value is given in views/devise/registrations/new.html.erb
for example:
<%= f.input :password_confirmation, :required => true %>
this gives out an input and a label, the label is * Password confirmation. How do I customize this label and the input field?
Thanks
<%= f.input :password_confirmation, :required => true, :label => 'something', :class => 'something' %>
Define the something class in CSS and you'll be fine.
And of course, generate the partials via copying from devise directly or using its generators. I usually copy them from devise repo since I am not that much fan of generators, sometimes they generate files I don't even need or want.
rails generate devise:views users
You will need to generate the partials first. After that you can use those generated files to override the default ones. Also, it might be good to build the authentication from scratch the first time in order to better understand the process.
http://railscasts.com/episodes/250-authentication-from-scratch

Rails formtastic is asking for a country plug-in.. I don't want it. Anyone know how to tell it I don't want it?

I'm using formtastic and I've got a field country.. I'm getting this error when I attempt to display the screen.
To use the :country input, please install a country_select plugin,
like this one: https://github.com/jamesds/country-select
Now. I don't want to use any plugin.. It's free text, and I want to keep it that way.
Anyone know how to remove this requirement? Should be easy as... but I'm buggered if I can see how.
= semantic_form_for #store, {:html => { :class => "form-horizontal" }} do |f|
= f.input :default_country
Add
, :as => :string
to the end of the line that's causing the error
= semantic_form_for #store, {:html => { :class => "form-horizontal" }} do |f|
= f.input :default_country, :as => :string
In Rails 4, formtastic with country select input field:
Add 'country-select' to your Gemfile:
gem 'country-select'
If I use semantic form select, it doesn't shows previously saved value. So, the following is not working properly:
=f.input :country, as: :select, collection: country_options_for_select
So have to use standard form elements to get working:
=f.select :country, collection: country_options_for_select
I found that this plugin works out of the box (note the underscore instead of the dash):
https://github.com/chrislerum/country_select

Resources