ぶろぐめんどくさい

技術系の記事と漫画レビューが入り混じった混沌

Bash on Ubuntu on WindowsでRails覚書

railsの導入で引っかかったところをまとめる。

参考

ここ->http://qiita.com/chimame/items/8130aa2c07a152a865b1を参考にrailsを導入。

サーバ起動時にエラーが発生

$ bundle exec rails s
=> Booting Puma
=> Rails 5.1.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Exiting
/home/user/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rb-inotify-0.9.8/lib/rb-inotify/watcher.rb:74:in `initialize': Invalid argument - Failed to watch "/mnt/c/Users/furik/Dropbox/work/rails/taskapp/config/locales": the given event mask contains no legal events; or fd is not an inotify file descriptor. (Errno::EINVAL)

bashはfile_watcherに対応していない->file_watcherを無効化。

config/environments/development.rb
- config.file_watcher = ActiveSupport::EventedFileUpdateChecker
+ #config.file_watcher = ActiveSupport::EventedFileUpdateChecker

Don’t know how to build task ‘rails’ (see –tasks)

参考 stackoverflow.com

bundle install --binstubsを実行

ルーティング

config/routes.rb

+ resources :projects
+ root 'projects#index'

Postできない

Rails4.0からの仕様? protect_from_forgeryを追加。

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :null_session
end

参考(http://nonbiri-tereka.hatenablog.com/entry/2014/09/03/104824)

Template is missing

render nothing: trueいらない。ステータスコード204だけどまあいいや。

bundle exec railsできない

gemのインストールパスを設定。

bundle install --path vendor/bundle

忘れがちなコマンド

  • bundle exec rails
  • rails g model Task title done:boolean project:references
  • rails g controller Tasks
  • rake db:migrate
  • rake routes