Railsでguardを使う。(rspec)
# Gemfile:
group :test do
gem 'rspec-rails'
gem 'guard-rspec'
# for Mac
gem 'rb-fsevent'
gem 'growl'
end
$ guard init rspec
$ guard start
Railsでguardを使う。(rspec)
# Gemfile:
group :test do
gem 'rspec-rails'
gem 'guard-rspec'
# for Mac
gem 'rb-fsevent'
gem 'growl'
end
$ guard init rspec
$ guard start
deviseでログイン後のURLを設定する方法。
deviseではログイン後にはデフォルトでroot_pathに移動するようになってる。それを変えたい。
devise / lib / devise / controllers / helpers.rb
def after_sign_in_path_for(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
home_path = "#{scope}_root_path"
respond_to?(home_path, true) ? send(home_path) : root_path
end
上記の様にresource(普通はUser)のroot_pathが設定されてればそっちに行くようになってるので下記の様にuser_root_pathに何かを設定すればいい。
# config/routes.rb:
Foo::Application.routes.draw do
match '/snippets' => 'snippets#index', :as => :user_root
end
ログイン後に/snippetsに行くようになった。
% gem install haml2slim
% ls app/views/emotions
_form.html.haml edit.html.haml index.html.haml new.html.haml show.html.haml
% haml2slim app/views/emotions
% ls app/views/emotions
_form.html.haml _form.html.slim edit.html.haml edit.html.slim index.html.haml index.html.slim new.html.haml new.html.slim show.html.haml show.html.slim
# app/views/emotions/show.html.slim:
p#notice= notice
p
b Body:
= @emotion.body
p
b Kind:
= @emotion.kind
= link_to 'Edit', edit_emotion_path(@emotion)
= link_to 'Back', emotions_path
OMG!
Generators Slim - Issues - plataformatec/devise - GitHubI'm exec this generate for slim, but the code created is erb...
$ rails g devise:views usuarios -e slim create app/views/usuarios create app/views/usuarios/confirmations/new.html.erb create app/views/usuarios/mailer/confirmation_instructions.html.erb create app/views/usuarios/mailer/reset_password_instructions.html.erb create app/views/usuarios/mailer/unlock_instructions.html.erb create app/views/usuarios/passwords/edit.html.erb create app/views/usuarios/passwords/new.html.erb create app/views/usuarios/registrations/edit.html.erb create app/views/usuarios/registrations/new.html.erb create app/views/usuarios/sessions/new.html.erb create app/views/usuarios/shared/_links.erb create app/views/usuarios/unlocks/new.html.erb
josevalim February 11, 2011 | link
You need devise master to do that.
READMEに書いてあるけど、deviseでhaml or slim(-eオプション)使いたかったら1.1.7じゃ駄目でmaster使えとのこと。1.2rcが正式になったら使えるようになるかも。
RubyでのUUIDのversion 1の使い方。
gem install uuid
>> require 'rubygems'
=> true
>> require 'uuid'
=> true
>> UUID.new
=> MAC: 58:55:ca:f3:26:47 Sequence: 9499
>> UUID.new.generate
=> "bc66c930-22f1-012e-251b-5855caf32647"
>> UUID.new.generate :compact
=> "be64e03022f1012e251b5855caf32647"
:compactはハイフンを取ってくれる。
How to use UUID Version 1 in Ruby.
:compact option omits the hyphens.
# Gemfile:
gem 'devise'
% bundle
% rails g devise:install
% rails g devise:views
% rails g devise user
% rails g controller home index
% rake db:migrate
# config/environments/development.rb:
Foo::Application.configure do
# ...
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end
# config/routes.rb:
Foo::Application.routes.draw do
root :to => 'home#index'
# ...
end
# app/views/layouts/application.html.erb:
<p><%= link_to 'Sign in', [:new, :user_session] %></p>
<p><%= link_to 'Sign up', [:new, :user_registration] %></p>
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<%= yield %>
% curl https://github.com/svenfuchs/rails-i18n/raw/master/rails/locale/ja.yml -o config/locales/ja.yml
% curl https://gist.github.com/raw/833169/54d19c523f6a608e732d4e9a6606a6d6cbec7f8e/devise.ja.yml -o config/locales/devise.ja.yml
いつもググってる気がするのでシリーズ。
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => 'postgresql',
:host => 'localhost',
:username => 'komagata',
:password => '',
:database => 'foo',
:port => 5432
)
class Post < ActiveRecord::Base
end
puts Post.first.name
% vagrant up
Vagrant has detected that you have VirtualBox version 3.2.12 installed!
Vagrant requires that you use at least VirtualBox version 4.0. Please install
a more recent version of VirtualBox to continue.
The Vagrant 0.6.x series supports VirtualBox 3.2, so if you're stuck with that
version, then please use the 0.6.x series of Vagrant.
Any earlier versions of VirtualBox are completely unsupported. Please upgrade.
VirtualBox 3.2系から4系へは自動アップデートが行われないので手動でアップデートする必要がある。忌々しい東京三菱UFJ銀行(法人版)とIE6の為に確保してあるWindows XP無印はアップデートしても問題無く動きました。
rubygemsを見ていて、ubygems.rbって変なファイルがあるなと思って開いたら・・・
# This file allows for the running of rubygems with a nice
# command line look-and-feel: ruby -rubygems foo.rb
lib/ubygems.rb at from rubygems/rubygems - GitHub
ナイスハックwww
% ls
% GEM_HOME=`pwd` gem list > /dev/null
% ls
cache doc gems specifications
なにそれこわい。
gem environmentとかでも同様。