草庐IT

android-multitouch-controller

全部标签

ruby-on-rails - 如何防止 Rails Controller 生成器修改 config/routes.rb

有时我会运行类似railsgcontrollerfooindex的命令来生成Controller和模板的骨架。因为我不希望每个Controller都有助手和Assets,所以我将以下代码放入config/application.rb:config.generatorsdo|g|g.helperfalseg.assetsfalseend还有一件事我不想发生。生成器将一行get"foo/index"添加到我的config/routes.rb。我该如何预防? 最佳答案 从Rails4.2开始,可以在application.rb中使用以下代

ruby-on-rails - 在 Controller 中找不到 namespace 内的 Ruby on Rails 模型

我是Rails的新手,无法弄清楚这个问题...我有一个ControllerAdmin::Blog::EntriesController在app/controllers/admin/blog/entries_controller.rb中定义我有一个模型叫做Blog::Entry定义在app/model/blog/entry.rb当我尝试从Controller访问我的模型时,我从这一行得到一个"uninitializedconstantAdmin::Blog::EntriesController::Blog":@blog_entries=Blog::Entry.find(:all)很明显,

ruby-on-rails - 我真的应该测试 Controller 吗?

我正在尝试获得最佳的代码覆盖率/开发时间结果目前我使用rspec+shoulda来测试我的模型,使用rspec+capybara来编写我的验收测试。我尝试为一个简单的crud编写一个Controller测试,但它花费的时间太长了,最后我得到了一个令人困惑的测试(可能是我的错)使用rspec进行Controller测试的最佳实践是什么?这是我的测试和我的Controller的要点(一个测试还没有通过):https://gist.github.com/991687https://gist.github.com/991685 最佳答案 也

ruby-on-rails - 如何在没有 CRUD 操作的情况下路由 Controller ?

我有一个包含许多操作的Controller:classTestsController当我像这样将它添加到我的routes.rb文件中时:resources:tests并执行rakeroutes任务我看到以下额外回合:testsGET/tests(.:format)tests#indexPOST/tests(.:format)tests#createnew_testGET/tests/new(.:format)tests#newedit_testGET/tests/:id/edit(.:format)tests#edittestGET/tests/:id(.:format)tests#s

ruby-on-rails - 无法覆盖设计密码 Controller

在我提交电子邮件以向我发送重置密码说明后,我需要我的Rails应用程序重定向到主页。设计,默认情况下在输入电子邮件后呈现登录表单。所以我试图覆盖Devise::PasswordsController并更改其redirect_to,但没有成功。事实上,我认为Rails甚至都没有上过我的课。这可能是一个非常愚蠢的错误,但我已经研究了半天,但没有成功。我的想法是覆盖here中的密码Controller.这是我的Controller:classPasswordsController路线.rb:devise_for:users,:controllers=>{:passwords=>"passwo

ruby-on-rails - 重命名 Rails 中的 Controller 并清除生成的内容

我一直在关注关于restful_authentication插件的railscast。他建议运行命令:脚本/生成经过身份验证的用户session我这样做了,一切都“很好”,但随后session将无法正常工作。再次检查该站点,他提到了一个命名标准并列出了更新的代码,其中声明:脚本/生成经过身份验证的用户sessionsession多元化。所以现在我有session_controller.rb,里面有一个SessionController,但我猜按照命名标准,它正在寻找SessionsController,导致代码失败并出现错误“NameErrorinSessionsController#

ruby-on-rails - 来自 Rails 4 中 Controller 的带有 html_safe 的 Flash 消息(安全版本)

在我的Controller中,我有以下代码:format.html{redirect_tonew_customer_url,notice:%Q[Acustomeralreadyexistswithwiththisshoppingid.Editthiscustomer#{view_context.link_to("here",edit_customer_url(@duplicate))}.].html_safe我希望能够在Flash消息中包含一个链接,因此(如您所见)我调用html_safe来取消转义该字符串。然而,从Rails4.1开始,这似乎有了不同的处理方式。(参见here和her

ruby-on-rails - Rails 仪表板设计 : one controller action per div

作为Rails的新手(更像是基础设施专家),我正在实现一个仪表板。仪表板将由多个页面组成,每个页面将包含多个图表/表格/等。对于模块化,我希望添加新图表或更改数据View尽可能简单。假设一页有5个不同的图表。我可以让Controller进行5次单独的数据查找,将所有相关数据保存在实例变量中,并呈现5个部分,每个部分都涉及数据的子集。但是看起来更模块化的是有一个“索引”ControllerAction,它的渲染有一堆div,并且对于每个div都有另一个ControllerAction,它进行数据查找并有一个相关的View部分负责管理该数据的View在分区内。因此,如果我要显示包含两个图表

ruby-on-rails - rails : use jbuilder template in various controller methods

是否可以在另一个Controller方法中重用jbuilder-template?换句话说:如何明确地说Controller方法使用具体的jbuilder-template? 最佳答案 来自Railsguide.从另一个Controller渲染一个Action的模板。Whatifyouwanttorenderatemplatefromanentirelydifferentcontrollerfromtheonethatcontainstheactioncode?Youcanalsodothatwithrender,whichacce

ruby-on-rails - URI::InvalidURIError: 错误的 URI(不是 URI?)测试 Rails Controller

我得到URI::InvalidURIError测试RailsHomeController:require'test_helper'classHomeControllerTest得到以下错误:EError:HomeControllerTest#test_should_get_index:URI::InvalidURIError:badURI(isnotURI?):http://www.example.com:80indextest/controllers/home_controller_test.rb:7:in`blockin'堆栈如下:Rails5.0.0.beta3minitest(