Skip to content

Instantly share code, notes, and snippets.

@boxnos
Last active December 18, 2015 05:49
Show Gist options
  • Save boxnos/5735229 to your computer and use it in GitHub Desktop.
Save boxnos/5735229 to your computer and use it in GitHub Desktop.
主にRailsのメモ。

Railsのメモ

ゆるいメモ。3.2用。

routes

RESTfulな感じに

コントローラーentriesに対して、

resources :entries

で、RESTfulな感じになる。

が、/entries.jsonとか、.xmlとかにも反応しちゃう、実装が面倒だ。

resources :entries , format => false

反映。

% rake routes
   entries GET    /entries          entries#index
           POST   /entries          entries#create
 new_entry GET    /entries/new      entries#new
edit_entry GET    /entries/:id/edit entries#edit
     entry GET    /entries/:id      entries#show
           PUT    /entries/:id      entries#update
           DELETE /entries/:id      entries#destroy

すっきり!

ログうざい

Gemfileに

group :development do
  gem 'thin'
  gem 'rails-clean-logs'
end

bootswatch導入

twitter-bootstrap-rails導入後、以下のコマンドを。テーマはお好みで。

theme=flatly
mkdir vendor/assets/stylesheets/bootswatch
wget -P vendor/assets/stylesheets/bootswatch http://bootswatch.com/$theme/variables.less
wget -P vendor/assets/stylesheets/bootswatch http://bootswatch.com/$theme/bootswatch.less

ちなみに、1行で書くと、

wget -P vendor/assets/stylesheets/bootswatch http://bootswatch.com/$theme/{variables,bootswatch}.less

こだね。

で、颯爽とvimを立ち上げて、3行目辺りに以下に追加。 vim app/assets/stylesheets/bootstrap_and_overrides.css.less

@import "bootswatch/variables.less";
@import "bootswatch/bootswatch.less";

twitter-bootswatch-rails + slim環境

twitter-bootstrap-railsのbootstrap3の対応がイマイチなので、導入してみる。

ほぼマニュアル通りに進める。

とりあえずプロジェクトをでっち上げ。

% rails new bootswatch-slim
% cd $_

色々追加。

gem 'therubyracer', platforms: :ruby # 有効に

gem 'slim-rails'

gem 'twitter-bootswatch-rails', github: 'scottvrosenthal/twitter-bootswatch-rails'
gem 'twitter-bootswatch-rails-helpers'

初期設定。

% bundle install
% rails g bootswatch:install flatly
% rails g bootswatch:import flatly
% rails g bootswatch:layout flatly

zshワンライナ。

% for i in {install,import,layout}; rails g bootswatch:$i flatly

layoutの変更。

class ApplicationController < ActionController::Base
  # ...
  layout 'flatly'
end

テスト。

% rails g scaffold Post title:string description:text
% rake db:migrate
% rails g bootswatch:themed Posts
  • slimのlayoutはショボイ。
  • 何故だかmigrate後じゃないと、themed出来ない。
  • _formにform-controlが付かないので、手動で付ける事。

slimも少し。production時は読みやすくする。 config/initializers/slim.rb辺りに、

Slim::Engine.set_default_options :pretty => true unless Rails.env == 'production'

要再起動。

pry + Rails

Railsのコンソールをステキにする。

Gemfileに以下をぶち込む

group :development do
  gem 'minitest'
  gem 'pry'
  gem 'pry-doc'
  gem 'pry-rails'
end

インストールして、コンソールを立ち上げる。

% bundle install
% rails console

ステキ。

bootstrapのメモ

  • less/variables.lessの中に設定が書いてあるのでいじればオケー

Markdownのメモ

はて、リンクはどう貼るんだろう。

http://www.google.com/

自動でリンクが貼られるようだけど、面倒だmakelink作らないとなぁと。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment