MiniMagickを使ってRMagickと決別する。
MiniMagickはImageMagickのRuby bindingじゃなくて、ImageMagickのCommand Line InterfaceのWrapper。Paperclipのアプローチに関心してたけど本来はこういうのをPaperclipが使うべきですね。
関連:RailsからImageMagick(convert)に自由にオプションを渡せると聞いて飛んできました - komagata
MiniMagickを使ってRMagickと決別する。
MiniMagickはImageMagickのRuby bindingじゃなくて、ImageMagickのCommand Line InterfaceのWrapper。Paperclipのアプローチに関心してたけど本来はこういうのをPaperclipが使うべきですね。
関連:RailsからImageMagick(convert)に自由にオプションを渡せると聞いて飛んできました - komagata
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!
Gmailのロックを外す方法。
Gmailでは短期間に何度もログインしたりするとアカウントにロックがかかるらしい。下記の方法でロックを解除できる。
クライアントでユーザー名とパスワードが受け入れられません - Gmail ヘルプ
[PASSWORD]:535-5.7.1 Username and Password not accepted. Learn more at
[PASSWORD]:535 5.7.1 http://mail.google.com/support/bin/answer.py?answer=14257
MUAのログには上記のように出るが、Railsのエラーでは1行目しか出ないのでロックがかかっていることに気付くのが難しい・・・。
RailsでGmailを使ってメールを送る。(Google Appsも可)
# config/environments/development.rb:
(...)
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'example.com',
:user_name => 'foo@example.com',
:password => 'password',
:authentication => 'plain',
:enable_starttls_auto => true
}
(...)
下記を設定しないとエラーを表示してくれないところに注意する。
config.action_mailer.raise_delivery_errors = true
Send email with Rails by using Gmail. (Google Apps too)
If the following are not set, the error is not displayed.
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が正式になったら使えるようになるかも。
$ sudo -s
# bash < <( curl -L http://bit.ly/rvm-install-system-wide )
# rvm install 1.8.7
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