#5 楼 @zj0713001 我看了下测试,不是Object.name
,ActiveSupport::Autoload.name # "ActiveSupport::Autoload"
,但是我不会 binding,不知道 binding 意思
module MyLib
extend ActiveSupport::Autoload
autoload :Model
eager_autoload do
autoload :Cache
end
end
MyLib.name # => "MyLib"
test "the location of autoloaded constants defaults to :name.underscore" do
module ::Fixtures::Autoload
autoload :SomeClass
end
assert !$LOADED_FEATURES.include?(@some_class_path)
assert_nothing_raised { ::Fixtures::Autoload::SomeClass }
end
test "the location of :eager autoloaded constants defaults to :name.underscore" do
module ::Fixtures::Autoload
eager_autoload do
autoload :SomeClass
end
end
assert !$LOADED_FEATURES.include?(@some_class_path)
::Fixtures::Autoload.eager_load!
assert $LOADED_FEATURES.include?(@some_class_path)
assert_nothing_raised { ::Fixtures::Autoload::SomeClass }
end
自动生产 migration,model,controller,view 等的模板文件,通常继承Rails::Generator::NamedBase
或者Rails::Generator::Base
https://github.com/rails/rails/tree/master/railties/lib/rails/generators
#12 楼 @chairy11 部署到一台服务器一般不用写 server 那部分
server 'xxx', user: 'root', roles: %w{web app}, my_property: :my_value
就可以了
地址是你本机的私钥地址
# server 'example.com',
# user: 'user_name',
# roles: %w{web app},
# ssh_options: {
# user: 'user_name', # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(publickey password)
# # password: 'please use keys'
# }
~/.ssh/config
Host bitbucket.org
User flowerwrong
Hostname bitbucket.org
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_bitbucket
Host github.com
User flowerwrong
Hostname github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github
Host ip
IdentityFile ~/.ssh/id_rsa_xx
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm' # 看下是不是没有加入rvm
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
手动git pull最新代码
不用,cap production deploy:check
会创建基础环境,过后cap production deploy
要不先玩这个 demo 吧
[email protected]:FlowerWrong/capdemo.git
# https://github.com/FlowerWrong/capdemo/blob/master/config/deploy.rb
set :deploy_to, '/home/ubuntu/www/capdemo'
# https://github.com/FlowerWrong/capdemo/blob/master/config/deploy/production.rb
role :app, %w{ubuntu@xxx}
role :web, %w{ubuntu@xxx}
role :db, %w{ubuntu@2xxx}
# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server definition into the
# server list. The second argument is a, or duck-types, Hash and is
# used to set extended properties on the server.
server 'xxx', user: 'ubuntu', roles: %w{web app}, my_property: :my_value
昨天听你说你的 gemfile.lock 里面 cap 是 2,你把他删掉,重新重新 bundle install 试下
rm Gemfile.lock
bundle install
[email protected]:FlowerWrong/capdemo.git
Engine is a gem. Rails is also a gem with many dependency gem.
To see demonstrations of other engines, check out Devise
, an engine that provides authentication for its parent applications, or Forem
, an engine that provides forum functionality. There's also Spree
which provides an e-commerce platform, and RefineryCMS
, a CMS engine.
换句话说,engine 更像一个模块。
建议先学习配置 ssh 连接自己服务器,github,bitbucket. 再回头就简单多了。
可以的,但推荐新建 migration
第二个问题:先rake db:drop
问题 1:你的本地工作环境中就可以,至于development
还是test
,或者tools
,无所谓,他只是一个cli
程序,
在 3 里面,cap production deploy
默认就是在rails
的production
环境下执行命令。
问题 2: require: false
就是不加载进入 rails 内部,也就是你不能在 rails 里面的文件里面直接用他或者没必要用它
。
问题 3:不知道了。
capistrano (3.2.1)
i18n
rake (>= 10.0.0)
sshkit (~> 1.3)
capistrano-bundler (1.1.3)
capistrano (~> 3.1)
sshkit (~> 1.2)
capistrano-rails (1.1.2)
capistrano (~> 3.1)
capistrano-bundler (~> 1.1)
capistrano-rvm (0.1.2)
capistrano (~> 3.0)
sshkit (~> 1.2)
:sym
比 'sym'
看起来爽
get '*path1/*path2/*path3' => 'pages#unknown'
我确实没有更好的解决办法了
#2 楼 @bianlimit 和 rails 没关系,你应该学习 html , css , javascript
<div class="">
<div class="a"></div>
<div class="b"></div>
<div class="c"></div>
</div>
http://guides.rubyonrails.org/routing.html
get '*path' => 'pages#unknown'
这个勉强符合需求,更好的我自己也没有发现.
例如我新建了一个 about 页面,在 page 这个 model 里面,那么我想他的路由是 pages/about,在 unknown action 里面我查找 about 这个关键字,返回 page model.
# routes.rb
get '*path' => 'pages#unknown'
# page_controller.rb
class PageController < ApplicationController
def unknown
@element = find_by_title(params[:path])
end
end
http://stackoverflow.com/questions/18481458/dynamic-routes-on-runtime-in-rails
模型1
class Course < ActiveRecord::Base
has_many :datums # not datum
end
http://api.jquery.com/focus/
http://api.jquery.com/blur/
http://api.jquery.com/jQuery.ajax/
......
namespace :admin do
resources :posts, :comments
end
# 对应controller在controller/admin/xxx_controller.rb
scope '/admin' do
resources :posts, :comments
end
# 对应controller在controller/xxx_controller.rb
就是多了一个 admin 空间,看你自己的需求了。 我一般配合 cancancan,就用第二种。
Akira Matsuda
黄家驹
参考新浪微博,微信 api 的设计
"Ruby": {
"ruby": "~/.rvm/rubies/default",
"rubyExtraPaths": ["~/.rvm/gems/ruby-2.1.4"]
}
ubuntu 14.04 work for me
参考 http://hyperneetprogrammer.hatenablog.com/entry/2014/09/14/001053 maybe help
"Ruby": {
"ruby": "~/.rvm/rubies/default",
"rubyExtraPaths": ["~/.rvm/gems/ruby-2.1.1"]
}