草庐IT

requester_name

全部标签

ruby-on-rails - 助手设计 : could not find the `Warden::Proxy` instance on request environment

我尝试将Devise用于我的Rails应用程序。我可以注册并登录,但是当我转到其他页面“构建”时,出现以下错误:Devise::MissingWardeninHome#showDevisecouldnotfindtheWarden::Proxyinstanceonyourrequestenvironment.MakesurethatyourapplicationisloadingDeviseandWardenasexpectedandthattheWarden::Managermiddlewareispresentinyourmiddlewarestack.Ifyouareseeing

ruby-on-rails - 项目 :Class 的未定义方法 `model_name'

我已经查看了所有相关问题,但对我来说没有什么新鲜事。我有一个带有"new"Action的项目ControllerclassProjectsController项目是一个简单的类,不是事件记录:classProjectattr_accessor:name,:descriptiondefinitialize@name=""@description=""endend我得到错误“项目:类的未定义方法‘model_name’”这是一个erb文件示例:: 最佳答案 如果Project不是事件记录子类,你需要这些,你可以使用form_forcla

ruby - 试图理解 self.method_name 与 Classname.method_name 在 Ruby 中的使用

我试图了解何时使用self.method_name与何时使用Classname.method_name。在下面的示例中,为什么“before_create”需要引用“User.hash_password”而不是“self.hash_password”或只是“hash_password”?由于我们已经在User类中,我认为before_create方法会“知道”“hash_password”是它自己的类的成员,不需要任何特殊语法来引用它。require'digest/sha1'classUser["name=?andhashed_password=?",name,hashed_passw

ruby-on-rails - 回形针错误 : model missing required attr_accessor for 'avatar_file_name'

然后我想使用Paperclip为每个列表拍摄照片。我向listshow.html.erb、listing.rb模型、listings_controller.rb和_form.html.erb部分添加了适当的代码。当我尝试为list上传图片时出现此错误:Paperclip::ErrorinListingsController#updateListingmodelmissingrequiredattr_accessorfor'avatar_file_name'listings_controller的第44行:defupdaterespond_todo|format|if@listing.u

ruby-on-rails - rails : switch connection on each request but keep a connection pool

在我们的Rails应用程序中,我们需要根据请求的子域使用不同的数据库(每个国家/地区使用不同的数据库)。现在我们正在做类似于thisquestion中推荐的事情.也就是说,在每个请求上调用ActiveRecord::Base.establish_connection。但是itseemsActiveRecord::Base.establish_connection删除当前连接池并在每次调用时建立一个新连接。我做了这个快速基准测试,看看每次调用establish_connection和已经建立连接之间是否有任何显着差异:require'benchmark/ips'$config=Rails

ruby-on-rails - 未初始化常量 "Controller Name"

我的路由/资源和Controller有错误。我在routes.rb中有以下内容:#routes.rbresources:usersdoresource:scheduleend我在controllers/users/中设置了一个schedule_controller.rb,我认为它应该是:classUsers::ScheduleController运行rake:routes显示user_schedulePOST/users/:user_id/schedule(.:format)schedules#createnew_user_scheduleGET/users/:user_id/sche

ruby-on-rails - 未定义的方法 `name' 为 "actionmailer":String

我有一个旧版本的Rails项目,它是使用BrowserCMS构建的在配置/环境文件中RAILS_GEM_VERSION='2.3.4'unlessdefined?RAILS_GEM_VERSION所以我使用rvm安装了这个gems,所以我可以运行它$gemlist***LOCALGEMS***actionmailer(2.3.8,2.3.4)actionpack(2.3.8,2.3.4)activerecord(2.3.8,2.3.4)activeresource(2.3.8,2.3.4)activesupport(2.3.8,2.3.4)bundler(1.1.4)mysql(2.8

ruby - 获取名称错误 : `format' is not allowed as an instance variable name when testing instance variable with rspec

我有以下测试:let(:client){Descat::Client.new}describe'poblacio'doit'shouldsetformatcorrectly'doclient.poblacio('v1','json','dades')expect(client.instance_variable_get(:format)).toeq('json')endend我有以下正在测试的代码:moduleDescatclassClientBASE_URL='http://api.idescat.cat/'definitialize(attributes={})attributes

ruby-on-rails - 如何让 Rails 中的 named_scope 返回一个值而不是数组?

我想写一个namedscope从它的id中获取记录。例如,我有一个名为Event的模型,我想使用named_scope来模拟Event.find(id)future的灵active。我在我的模型中使用了这段代码:named_scope:from_id,lambda{|id|{:conditions=>['id=?',id]}}我从我的Controller调用它,如Event.from_id(id)。但我的问题是它返回一组Event对象而不是一个对象。因此如果我想获取事件名称,我必须写event=Event.from_id(id)event[0].name而我想要的是event=Even

ruby - 加载网页时 : "undefined method ` request_uri' for #"

我正在尝试使用Ruby通过HTTP加载网页并检查其状态代码是什么。我的代码如下所示:require"net/http"@r=Net::HTTP.get_response(URI.parse(myURL))return@r.code但是,对于某些URL(主要是指向奇怪的东西,例如不会给出正确响应的Web计数器),我得到了一个undefinedmethodrequest_urifor#异常。我已经将它追溯到http.rb的第380行(我正在运行Ruby1.8),它说:defHTTP.get_response(uri_or_host,path=nil,port=nil,&block)ifpa