草庐IT

Rails-Webpacker

全部标签

ruby-on-rails - 将 Rails/ClearDB App 推送到 Heroku 错误 'Can' t 连接到 '127.0.0.1' 上的 MySQL 服务器

每次我跑:gitpushherokumaster我收到以下错误:Running:rakeassets:precompilerakeaborted!Can'tconnecttoMySQLserveron'127.0.0.1'我在运行rails-vRails3.2.11和ruby-vruby1.9.3p194(2012-04-20revision35410)[x86_64-darwin12.2.0]我已经通过HerokuCLI安装了ClearDB,它似乎工作正常,但我无法找出这个错误。这是我用于生产的yml:production:adapter:mysql2encoding:utf8hos

ruby-on-rails - RSpec 测试自定义验证器

我的模型中有以下验证器:classContinuumValidator如何使用Rspec对其进行测试?这是我到目前为止所做的尝试:(感谢zetetic)describe"validationerror"dobeforedo@time_event=Hrm::TimeEvent.new(start_time:"2012-10-0510:00:00",end_time:"2012-10-0509:00:00",event_type:2)endit"shouldnotbevalidifendtimeislowerthanstarttime"do@time_event.should_notbe_

ruby-on-rails - 在 seeds.rb 中关闭验证

如何在seeds.rb中关闭Rails3.2.3中的验证?我这样做了u1=User.createemail:'my@email.com',password:'123',validate:false但它说无法批量分配protected属性:验证。我知道这是什么意思。那么我该如何摆脱这个错误呢? 最佳答案 你可以做到u1=User.new(email:'my@email.com',password:'123').save(validate:false) 关于ruby-on-rails-在se

ruby-on-rails - 提示需要散列的事件资源

我正在使用事件资源从api获取数据并显示它,我的Controllermodel.rb有classThr::Vol::Dom'/vv/test/domains/2013-06-25T05:03Z')xendend当我调用Thr::Vol::Dom.find方法时,它返回以下错误:ArgumentError:expectedanattributesHash,got["0.0.0.0","1.1.1.1","2.2.2.2","3.3.3.3","4.4.4.4"]该api应该提供这样的内容{"abs.com":["0.0.0.0","1.1.1.1","2.2.2.2","3.3.3.3"

ruby-on-rails - 如何在 Rails 中使用带有对象数组的强参数

使用Rails4.0强参数时,如何允许这样的JSON?{"user":{"first_name":"Jello"},"users_to_employer":[{"start_date":"2013-09-03T16:45:27+02:00","end_date":"2013-09-10T16:45:27+02:00","employer":{"company_name":"Telenor"}},{"start_date":"2013-09-17T16:45:27+02:00","end_date":null,"employer":{"company_name":"Erixon"}}]}

ruby-on-rails - 在 Rails 4 迁移中设置自定义主键时出现问题

我使用postgresql9.3、Ruby2.0、Rails4.0.0。在阅读了很多有关在表上设置主键的问题后,我生成并添加了以下迁移:classCreateShareholders我还在我的模型中添加了self.primary_key="uid"。迁移成功运行,但是当我使用pgAdminIII连接到数据库时,我看到uid列未设置为主键。我错过了什么? 最佳答案 看看thisanswer.尝试执行“ALTERTABLEshareholdersADDPRIMARYKEY(uid);”,而不在create_tableblock中指定pr

ruby-on-rails - 无法从 Rails 4 和 PSQL 9.3 中的表中删除索引

在我的schema.rb中有以下行:add_index"users",["email"],name:"index_users_on_email",unique:true,using::btree当我在psql中运行\di时,我得到:Schema|Name|Type|Owner|Table--------+--------------------------------------------------------------+-------+-------+-----------------------public|index_users_on_email|index|alex|us

ruby-on-rails - Rails 没有使用我的全局 Ruby 版本

我想将Rails与Ruby2.1.0结合使用,但它使用的是Ruby1.9.3(系统版本)。我正在使用rbenv管理我的Ruby版本。我的步骤是这样的:$rbenvinstall2.1.0$rbenvglobal2.1.0$sudogeminstallrails-v4.0.2$rbenvrehash$rbenvversionssystem*2.1.0(setby/home/dennis/.rbenv/version)$ruby-vruby2.1.0p0(2013-12-25revision44422)[x86_64-linux]$railsnewapp&&cdapp$railsserve

ruby-on-rails - 为 ActiveAdmin Controller 设置过滤器 before_action

我想向ActiveAdminController添加before_action过滤器。我可以这样做吗:before_action:set_product,only:[:show,:edit,:update,:destroy]privatedefset_product@product=Product.find_by_name(params[:name])end 最佳答案 您可以从controllerdo...endDSL中访问Controller:ActiveAdmin.registerUserdobefore_action:set_

ruby-on-rails - 从 rake 任务调用 Controller

我想从rake任务中调用Controller操作。我的问题是准备http请求的最佳方法是什么?感谢所有提示。编辑:有人有其他提示吗?我试过这个但没有用:controller_obj=Controller.newcontroller.your_method我遇到了这个异常:rakeaborted!uninitializedconstantController编辑2:我试过:sess=ActionController::Integration::Session.newsess.post('/route','codes=3')但是我得到了(我在rake文件中需要'action_control