k-yamadaのブログ

プログラミングのメモ

Rails3.28メモ

ホーム画面作成

簡単!Rails3.2を使って10分でブログアプリを構築する方法
http://dqn.sakusakutto.jp/2012/03/rails32blog.html

$ rails g controller home index
      create  app/controllers/home_controller.rb
       route  get "home/index"
      invoke  erb
      create    app/views/home
      create    app/views/home/index.html.erb
      invoke  test_unit
      create    test/functional/home_controller_test.rb
      invoke  helper
      create    app/helpers/home_helper.rb
      invoke    test_unit
      create      test/unit/helpers/home_helper_test.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/home.js.coffee
      invoke    scss
      create      app/assets/stylesheets/home.css.scss

$ rm public/index.html 
$ vim config/routes.rb 
root :to => 'home#index'

scaffold

Rails3のscaffoldを試す
http://d.hatena.ne.jp/toyoshi/20100903/1283476109

$ rails g scaffold question english:text javanese:text description:text
      invoke  active_record
      create    db/migrate/20121013154040_create_questions.rb
      create    app/models/question.rb
      invoke    test_unit
      create      test/unit/question_test.rb
      create      test/fixtures/questions.yml
      invoke  resource_route
       route    resources :questions
      invoke  scaffold_controller
      create    app/controllers/questions_controller.rb
      invoke    erb
      create      app/views/questions
      create      app/views/questions/index.html.erb
      create      app/views/questions/edit.html.erb
      create      app/views/questions/show.html.erb
      create      app/views/questions/new.html.erb
      create      app/views/questions/_form.html.erb
      invoke    test_unit
      create      test/functional/questions_controller_test.rb
      invoke    helper
      create      app/helpers/questions_helper.rb
      invoke      test_unit
      create        test/unit/helpers/questions_helper_test.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/questions.js.coffee
      invoke    scss
      create      app/assets/stylesheets/questions.css.scss
      invoke  scss
      create    app/assets/stylesheets/scaffolds.css.scss

$ rake db:migrate
==  CreateQuestions: migrating ================================================
-- create_table(:questions)
   -> 0.0121s
==  CreateQuestions: migrated (0.0121s) =======================================

jquery.mobile

参考:http://d.hatena.ne.jp/arcright/20120905/1346755680

1.公式サイトからzipをダウンロードして回答
http://jquerymobile.com/download/
Zip File: jquery.mobile-1.2.0.zip (JavaScript, CSS, and images)

2.ファイルを配置

$ mkdir app/assets/images/images
$ mkdir app/assets/images/images/jquery.mobile 
$ mkdir app/assets/stylesheets/jquery.mobile
$ cp ~/Downloads/jquery.mobile-1.2.0/images/* app/assets/images/images/jquery.mobile/
$ cp ~/Downloads/jquery.mobile-1.2.0/*.css app/assets/stylesheets/jquery.mobile/
$ rm app/assets/stylesheets/jquery.mobile/*min.css

3.cssのimageのパスを修正

$ vim app/assets/stylesheets/jquery.mobile/jquery.mobile.theme-1.2.0.css
%s/images/\/assets\/images\/jquery.mobile/g 

4.application.cssを編集

$ vim app/assets/stylesheets/application.css
/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the top of the
 * compiled file, but it's generally better to create a new file per style scope.
 *
 *= require_self
 *= require_tree .
 *= require_tree ./jquery.mobile
 */