スポンサーリンク

Rails5.0でbootstrap-sassとsimple_form(1)

https://github.com/plataformatec/simple_form
本家

http://blog.scimpr.com/2013/12/31/rails4-0%E3%81%A7bootstrap%E5%B0%8E%E5%85%A5%E3%81%AE%E3%81%82%E3%82%8C%E3%81%93%E3%82%8C%EF%BD%9Ebootstrap-sass-simple_form-kaminari-datatables/
Rails4.0でBootstrap導入のあれこれ~bootstrap-sass simple_form kaminari dataTables
2013/12/31     2015/03/22

http://tkymtk.hatenablog.com/entry/simpleform-with-bootstrap3-2014-01
2014-01-27
Rails4: Simple_formをBootstrap3に対応させて使う。

(1)sample2 アプリの作成

[sourcecode language=”bash” padlinenumbers=”true”]
rails new sample2
[/sourcecode]

(2) Gemfile の 17行目「# gem ‘therubyracer’, platforms: :ruby」の #を消して、
次の行に、

[sourcecode language=”ruby”]
gem ‘simple_form’
[/sourcecode]

を加える。

(訂正前)
image

(訂正後)
image

(3)ターミナルで、

[sourcecode language=”bash”]
cd sample2
bundle install
rails generate simple_form:install –bootstrap
[/sourcecode]

image

image

image

(4)scaffoldで、taskのcontroller, model, viewを作成

[sourcecode language=”bash”]
rails g scaffold task title:string name:string done:boolean
rails db:migrate
[/sourcecode]

image

image

以下、繰り返しになりますが、ほとんど、

http://blog.scimpr.com/2013/12/31/rails4-0%E3%81%A7bootstrap%E5%B0%8E%E5%85%A5%E3%81%AE%E3%81%82%E3%82%8C%E3%81%93%E3%82%8C%EF%BD%9Ebootstrap-sass-simple_form-kaminari-datatables/

のコピペです。

(5)app/models/task.rb を、以下のように書き換える。

[sourcecode language=”ruby”]
class Task < ActiveRecord::Base
validates :title, presence: true
end
[/sourcecode]

image

(6)ターミナルで、rails s -b 0.0.0.0

ブラウザで、 localhost:3000/tasks

image

image

(7)app/views/tasks/_forn.html.erb を、以下のように変更

[sourcecode language=”ruby”]
<%= f.button :submit, class: ‘btn btn-primary’ %>
[/sourcecode]

(変更前)
image

(変更後)
image

(8)config/initializers/simple_form.rb の64行目を、以下のように変更する。

[sourcecode language=”ruby”]
config.button_class = ‘btn btn-default’
[/sourcecode]

(変更前)
image

(変更後)
image

 

ーーーーーーー

bootstrap-sass も入れた。

initializer/simple-form.rb の、107行目

image

# config.default_form_class = nil

を、

config.default_form_class = ‘form_horizontail’

に変更

image

なかなかうまくいかない。あきらめるか。。。

今日は疲れたのでここまで

続きは明日以降に、、、

————–

次はこれをやりたい。

http://qiita.com/azusanakano/items/7fc27567254bed317313
Ruby on Rails 4 – bootstrap3+simple_form+datetimepicker
azusanakanoが2016/01/23に投稿(2016/03/06に編集)

スポンサーリンク