我有一个Rails应用程序,我试图在生产环境中测试.我跑了RAILS_ENV=production rake assets:precompile,它在/ public/assets中生成了我的所有资产.问题是,当我启动我的应用程序时,RAILS_ENV=production rails s thin我得到:
ActionController::RoutingError (No route matches [GET] "/assets/application-eff78fd67423795a7be3aa21512f0bd2.css"):
Run Code Online (Sandbox Code Playgroud)
这个文件确实存在于/public/assets/application-eff78fd67423795a7be3aa21512f0bd2.css.
有什么想法为什么我得到这个RoutingError?
我刚刚阅读了一篇博客文章,并注意到作者tap在一个片段中使用了类似于:
user = User.new.tap do |u|
u.username = "foobar"
u.save!
end
Run Code Online (Sandbox Code Playgroud)
我的问题是使用的好处或优势究竟是什么tap?我不能这样做:
user = User.new
user.username = "foobar"
user.save!
Run Code Online (Sandbox Code Playgroud)
或者更好的是:
user = User.create! username: "foobar"
Run Code Online (Sandbox Code Playgroud) 鉴于我Personable在我的Rails 4应用程序中有一个问题有一个full_name方法,我将如何使用RSpec进行测试?
关注/ personable.rb
module Personable
extend ActiveSupport::Concern
def full_name
"#{first_name} #{last_name}"
end
end
Run Code Online (Sandbox Code Playgroud) 我需要调整一些与iPhone状态栏高度相关的元素.我知道状态栏通常是20点高,但当它处于网络共享模式时不是这种情况.它被加倍到40.确定它的高度的正确方法是什么?我试过了
[[UIApplication sharedApplication] statusBarFrame]
Run Code Online (Sandbox Code Playgroud)
但它给了我20 x 480的景观,这是正确的,但它给了我320 x 40的肖像.它为什么不给我相反的(40 x 320)?
我试图bundle在OSX 10.9上运行我的Rails项目.pg使用此错误进入gem 时失败:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/kyledecot/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... yes
checking for PQconnectionUsedPassword()... yes
checking for PQisthreadsafe()... yes
checking for PQprepare()... yes
checking for PQexecParams()... yes
checking for PQescapeString()... yes
checking for PQescapeStringConn()... yes
checking for PQescapeLiteral()... yes
checking …Run Code Online (Sandbox Code Playgroud) 我有四个模型(Document,Question,Question::Document和Answer).在我的Answer模型中,我有
validates :text,
presence: { :unless => Proc.new{ |a| a.question.is_a? Question::Document } }
Run Code Online (Sandbox Code Playgroud)
这给了我警告
warning: toplevel constant Document referenced by Question::Document
如何防止发生此警告(不重命名我的课程)?
我正在创建一个红宝石宝石,我注意到(据我所知)似乎没有宝石的命名约定.例如,我见过两个:
gem 'foo-bar'
gem 'foo_bar'
Run Code Online (Sandbox Code Playgroud)
红宝石的命名是否有某种明确的指导/惯例?
ruby rubygems ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1
我有一个处理基于断码的用户密码的编辑定制控制器在这里.
用户模型
attr_accessible :password, :password_confirmation, :username, :login
...
devise :database_authenticatable,
:lockable,
:registerable,
:recoverable,
:rememberable,
:trackable
Run Code Online (Sandbox Code Playgroud)
PasswordsController
expose(:user) { current_user }
def update
if user.update_with_password(params[:user])
sign_in(user, :bypass => true)
flash[:notice] = "success"
else
render :edit
end
end
Run Code Online (Sandbox Code Playgroud)
我的编辑密码表单位于此处.
问题在于,无论我输入(或不输入该内容)到编辑密码表单中,都会显示"成功"闪存方法.
我正在尝试调试运行时我的应用程序试图连接到我的数据库的原因rake assets:precompile --trace.
我可能在堆栈跟踪中遗漏了一些东西......有人看到相关的线路吗?
DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in ActionController::Base instead. (called from <top (required)> at /Users/Kyle/Desktop/skateparks-web/config/application.rb:4)
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/bin/ruby /Users/Kyle/.rvm/gems/ruby-1.9.2-p290@skateparks/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in ActionController::Base instead. (called from <top (required)> at /Users/Kyle/Desktop/skateparks-web/config/application.rb:4)
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all …Run Code Online (Sandbox Code Playgroud) 我正在使用net/http来自Yahoo Placemaker API的一些json数据.收到响应后我正在执行JSON.parse响应.这给了我一个看起来像这样的哈希:
{"processingTime"=>"0.001493", "version"=>"1.4.0.526 build 111113", "documentLength"=>"25", "document"=>{"administrativeScope"=>{"woeId"=>"2503863", "type"=>"Town", "name"=>"Tampa, FL, US", "centroid"=>{"latitude"=>"27.9465", "longitude"=>"-82.4593"}}, "geographicScope"=>{"woeId"=>"2503863", "type"=>"Town", "name"=>"Tampa, FL, US", "centroid"=>{"latitude"=>"27.9465", "longitude"=>"-82.4593"}}, "localScopes"=>{"localScope"=>{"woeId"=>"2503863", "type"=>"Town", "name"=>"Tampa, FL, US (Town)", "centroid"=>{"latitude"=>"27.9465", "longitude"=>"-82.4593"}, "southWest"=>{"latitude"=>"27.8132", "longitude"=>"-82.6489"}, "northEast"=>{"latitude"=>"28.1714", "longitude"=>"-82.2539"}, "ancestors"=>[{"ancestor"=>{"woeId"=>"12587831", "type"=>"County", "name"=>"Hillsborough"}}, {"ancestor"=>{"woeId"=>"2347568", "type"=>"State", "name"=>"Florida"}}, {"ancestor"=>{"woeId"=>"23424977", "type"=>"Country", "name"=>"United States"}}]}}, "extents"=>{"center"=>{"latitude"=>"27.9465", "longitude"=>"-82.4593"}, "southWest"=>{"latitude"=>"27.8132", "longitude"=>"-82.6489"}, "northEast"=>{"latitude"=>"28.1714", "longitude"=>"-82.2539"}}, "placeDetails"=>{"placeId"=>"1", "place"=>{"woeId"=>"2503863", "type"=>"Town", "name"=>"Tampa, FL, US", "centroid"=>{"latitude"=>"27.9465", "longitude"=>"-82.4593"}}, "placeReferenceIds"=>"1", "matchType"=>"0", "weight"=>"1", "confidence"=>"8"}, "referenceList"=>{"reference"=>{"woeIds"=>"2503863", "placeReferenceId"=>"1", "placeIds"=>"1", "start"=>"15", "end"=>"20", "isPlaintextMarker"=>"1", "text"=>"Tampa", "type"=>"plaintext", "xpath"=>""}}}}
Run Code Online (Sandbox Code Playgroud)
我可以通过做某些事情来访问元素,jsonResponse['version']但我无法做到jsonResponse.version.为什么是这样?