I want to do a Toggle Switch on RoR
My versions of ruby on rails are respectively:
ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]
and
rails -v
Rails 5.1.3
I created a project with scaffold
rails new comprobar
cd comprobar
rails generate scaffold Articulo nombre:string titulo:string contenido:text comprobar:boolean
rails db:migrate
What can be displayed on github: link
I'm using the gem bootstrap-switch-rails
NOTE: If someone has some other gem and / or procedure in rails that I can serve, I'm glad to follow your suggestion.
What I have done so far is the following:
Following the steps on the page: link
I copied the gem bootstrap-switch-rails
to my gemfile
and another two more
gem 'bootstrap-switch-rails'
gem 'bootstrap3-rails', '~> 3.2'
gem 'bootstrap-sass', '~> 3.2.0'
I copied the respective js
and style
using sass
, as indicated by the page referenced and the code as indicated by the page in the respective _form.html.erb
<% content_for :head do %>
<script type="text/javascript">
$(document).ready(function() {
$('input:checkbox').bootstrapSwitch();
});
</script>
<% end %>
<div class="field">
<%= form.label :comprobar %>
<%= form.check_box :comprobar,
:data => { :size=>'small', 'on-color'=>'success', 'on-text'=>'YES', 'off-text'=>'NO' } %>
</div>