3. What is Ruby on Rails?
Ruby on Rails, often simply Rails, is an
open source web application framework
which runs on the Ruby programming
language.
• Ruby on Rails emphasizes the use of
well-known software engineering patterns
and principles, such as active record
pattern, convention over configuration
(CoC), don't repeat yourself (DRY), and
model–view–controller (MVC).
- wikipedia.org
•
「安心・安全・安定・信頼」できるインターネットサービスを
!3
4. What is Ruby on Rails?
「安心・安全・安定・信頼」できるインターネットサービスを
!4
5. Ruby on Rails tutorial
「安心・安全・安定・信頼」できるインターネットサービスを
!5
6. What is Twitter bootstrap?
Bootstrap is a free collection of
tools for creating websites and web
applications. It contains HTML and
CSS-based design templates for
typography, forms, buttons, navigation
and other interface components, as
well as optional JavaScript
extensions.
•
- wikipedia.org
「安心・安全・安定・信頼」できるインターネットサービスを
!6
12. Edit application css for BS
•
to use bootstrap, edit app/assets/
stylesheets/application.css
!
% mv app/assets/stylesheets/application.css{,.scss}
% vi app/assets/stylesheets/application.css.scss
(delete all line, and add two lines below.)
!
@import "twitter/bootstrap";
body { padding-top: 70px; }
「安心・安全・安定・信頼」できるインターネットサービスを
!12
13. Edit application.js
•
to use bootstrap, edit app/assets/
javascript/application.js
!
% vi app/assets/javascripts/application.js
!
//=
//=
//=
//=
//=
•
require jquery
require jquery_ujs
require turbolinks
require twitter/bootstrap
require_tree .
← add this line.
Initial setup was completed.
「安心・安全・安定・信頼」できるインターネットサービスを
!13
14. App example
•
at the top directory of rails project,
scaffolding blog post application.
!
% rails g scaffold Post title:string description:text
% rake db:migrate
•
You can check your app, access to http://localhost:3000/posts/ .
Invoke rails server.
!
% rails s
「安心・安全・安定・信頼」できるインターネットサービスを
!14
16. Decorate app (all view)
•
!
Edit app/views/layouts/application.html.erb
% vi app/views/layouts/application.html.erb
→ Continue to the next page.
「安心・安全・安定・信頼」できるインターネットサービスを
!16
24. How to use bootswatch(cerulean)
•
Fetch css from official site.
% mkdir vendor/assets/stylesheets/bootswatch
% cd !$
% curl -O http://bootswatch.com/cerulean/bootstrap.css
•
Edit application css.
% vi app/assets/stylesheets/application.css.scss
@import 'twitter/bootstrap';
← remove this line.
@import ‘bootswatch/bootstrap'; ← add this line.
「安心・安全・安定・信頼」できるインターネットサービスを
!24
27. How to use pagination(kaminari) with BS3
•
Edit Gemfile.
!
:
gem ‘kaminari'
:
•
re-bundle.
!
% bundle install --path vendor/bundle
「安心・安全・安定・信頼」できるインターネットサービスを
!27
28. Generate pagination's view
% rails g kaminari:views bootstrap
•
This generator will create BS2 view,
patch below:
app/views/kaminari/_paginator.html.erb
- <div class="pagination">
<ul>
+ <div>
+
<ul class="pagination">
「安心・安全・安定・信頼」できるインターネットサービスを
!28
29. Pagination example
•
!
!
!
Edit post controller.
% vi app/controllers/posts_controller.rb
def index
@posts = Post.all
end
↓
def index
@posts = Post.all
@posts = @posts.page(params[:page]).per(3) # 3 posts/page
end
「安心・安全・安定・信頼」できるインターネットサービスを
!29
30. Pagination example
•
!
Edit post index view.
% vi app/views/posts/index.html.erb
<%= paginate @posts %> ← add this line to bottom of listing.
「安心・安全・安定・信頼」できるインターネットサービスを
!30
34. •
Thank You!
•
If you have any comments,
•
please send to:
•
Mail: izawa@izawa.org / izawa@clwit.co.jp
•
Twitter: @Yukimitsu_̲Izawa
「安心・安全・安定・信頼」できるインターネットサービスを
!34