んじゃあ、まあ、また作り直しだよw
ゼッテー、幾つも上げたエントリー、ごっそり消すようなヘマ、またやらかすぜ?
オレ。
まあ、いいよwww
どうせ俺のメモ替わりでしかないんだから。
bloggerで書いてたことを、もう一度、やり方変えてやり直すことにした。
とりあえず、やること。
- プロジェクトの作成
- capistoranoでdeploy
- restful_authenticationとaasmとrole_requirementを使って認証
- restful_authentication _tutorialを参考に、車輪の再開発
- i18nは、後回しにする。
んな感じ。
とりあえず、プロジェクトの再作成。
$ mkdir ~/Rails $ cd ~/Rails $ rails hogehoge
んで、リポジトリにインポート。
$ mkdir /var/reositories $ mkdir /var/repositories/hogehoge $ svnadmin create /var/repositories/hogehoge $ svn import -m "Import Project 'hogehoge'" ./hogehoge svn+ssh://localhost/var/repositories/hogehoge/trunk
んで、チェックアウト。
$ mv ./hogehoge ./hogehoge_imported $ svn checkout svn+ssh://localhost/var/repositories/hogehoge/trunk ./hogehoge $ cd hogehoge
んじゃあ、capistranoのセットアップ。
$ capify . $ mate ./ #<=TextMateだこのヤロー
んで。
config/deploy.rb
set :application, "hogehoge" set :repository, "svn+ssh://*ユーザ*@localhost/var/repositories/#{application}/trunk" # If you aren't deploying to /u/apps/#{application} on the target # servers (which is the default), you can specify the actual location # via the :deploy_to variable: # set :deploy_to, "/var/www/#{application}" # If you aren't using Subversion to manage your source code, specify # your SCM below: # set :scm, :subversion set :scm, :subversion role :app, "localhost" role :web, "localhost" role :db, "localhost", :primary => true set :use_sudo, false set :runner, "*ユーザ*" #set :user do Capistrano::CLI.ui.ask('SSH User: ') end set :user, "*ユーザ*" #set :password do Capistrano::CLI.password_prompt('SSH Password: ') end set :password, "*パスワード*" set :deploy_to, "/var/rails_apps/#{application}" namespace :mod_rails do desc <<-DESC Restart the application altering tmp/restart.txt for mod_rails. DESC task :restart, :roles => :app do run "touch #{File.join(deploy_to, current_dir)}/tmp/restart.txt" end end namespace :deploy do %w(start restart).each { |name| task name, :roles => :app do mod_rails.restart end } end default_run_options[:pty] = true # [err] Permission denied (publickey,password,keyboard-interactive) # default_environment["PATH"] = "/opt/local/bin:/opt/local/sbin/:/opt/local/apache2/bin:{$PATH}" #ssh_options[:verbose] = :debug task :dump_env do run "echo $PATH" end
んで、aasmインストール。
$ sudo gem sources -a http://gems.github.com # (you only need to do this once) $ sudo gem install rubyist-aasm
んで、restful_authentication
$ git clone git://github.com/technoweenie/restful-authentication.git vendor/plugins/restful_authentication #<=ディレクトリ名に「-」が入っているとrailsがエラーを返すので、「_」を指定してインストール
んで、ジェネレート。
$ script/generate authenticated user sessions --aasm
んで、role_requiredプラグインのインストール。
$ git://github.com/timcharper/role_requirement.git
んで、ジェネレート。
$ script/generate roles Role User
んじゃあ、aasmを有効に。
app/controller/application.rb
+ require 'aasm'
んじゃあ、restful_authenticationのメール認証の為のオブザーバを設定。
config/environment.rb
require File.join(File.dirname(__FILE__), 'boot') +#Load application and environment specific constants +raw_config = File.read(RAILS_ROOT + "/config/config.yml") +APP_CONFIG = YAML.load(raw_config)[RAILS_ENV] + Rails::Initializer.run do |config| (略) # Please note that observers generated using script/generate observer need to have an _observer suffix # config.active_record.observers = :cacher, :garbage_collector, :forum_observer + config.active_record.observers = :user_observer end
んじゃあ、諸々の定数の設定。
restful_authentication _tutorialを参考に(つうか、丸パクリ)。
config/config.yml (新規作成)
development: settings: name: Your Application domain: localhost:3000 session_key: _your_application_session secret: 1138371c71fe2f4f6769090e9fa0d7314b4febcc1c1966f9c83e16a3c880e0ca396cbb37e9ce53bbefc2417cb7363d7127200d51f16b9aeda033dbc3600c63fc forgery: b8029fa60066bb90d7fb4e68265a112b admin_email: yourpersonalemail@example.com in_beta: true new_user_invite_limit: 5 max_user_invite_limit: 100 rest_auth: site_key: e587f9d09baa59c920b9ee97ac70f58b3c51356c stretches: 10 mail: address: mail.yourapplication.com port: 25 domain: yourapplication.com authentication: :login user_name: email_account_username_or_address@yourapplication.com password: emailaccountpassword sender: donotreply@yourapplication.com recaptcha: publickey: privatekey:
んじゃあ、mailのイニシャライザ
config/inisializer/mail.rb(新規作成)。
# Email settings ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.smtp_settings = { :address => 'your.smtp.domain', :port => 587, :domain => 'hogehoge.com', :authentication => :login, :user_name => 'username', :password => 'password' }
んじゃあ、ルーティングの設定。
config/routes.rb
- map.resources :users + map.activate '/activate/:activation_code', :controller => 'users', :action => 'activate', :activation_code => nil + map.resources :users, :member => { :suspend => :put, + :unsuspend => :put, + :purge => :delete }
んな感じ。
マイグレートはまだしない。
スキーマ、書き換えて、初期データ用意してから。
さて、いつまで書き続けられるかな?www