jjzjj

process-control

全部标签

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(

ruby - Rails 3 - 测试 Controller 的 GET 方法 - 尝试使用 JSON 并出现 406 错误

我有一个简单的Controller,它指定:respond_to:json当我尝试构建这样调用它的功能测试时:test"GET"doget'index',:format=>:jsonend一切正常。但是,如果我尝试像这样传递查询参数:test"GET"doget'index',{:my_param='1234'},:format=>:jsonend我收到Controller返回的406错误。如果我通过response.inspect转储响应,我可以看到@status=406和@header的内容类型为文本/html。如果我通过response.inspect为不传递查询参数的简单情况转

ruby-on-rails - 将参数从 View 传递到 Controller

我有一个新手问题。我正在尝试将一个变量从我的View传递到我的Controller。无论如何,我的Controller中的方法是否可以从我的View接收变量?Postview:show.html.erb:....:add_relationship(@rela)%>Controller:post.controller.rb:defadd_relationship(rela)@post=Post.find(params[:id])ifcurrent_user.id==@post.user_id@post.rel_current_id=rela.id@post.saveredirect_to

ruby-on-rails - 在 rails3 的 Controller 上使用 number_with_precision

我想在Controller上使用这个辅助方法。有什么办法可以实现吗? 最佳答案 可能不是一个好主意,但如果必须,请像这样包含帮助程序:classWhateverControllerincludeActionView::Helpers::NumberHelperdefshowrender:text=>number_with_precision(2342.234,:precision=>2)endend 关于ruby-on-rails-在rails3的Controller上使用number_

ruby - 多个 Controller 之间共享的 before_filter 放在哪里

我有多个Controller,它们都使用相同的before_filter。为了让事情保持干燥,这个方法应该放在哪里以便所有Controller都可以使用它?模块似乎不是正确的位置,但我不确定为什么。我不能将它放在基类中,因为Controller已经有不同的父类(superclass)。 最佳答案 如何将您的before_filter和方法放在一个模块中,并将其包含在每个Controller中。我会将此文件放在lib文件夹中。moduleMyFunctionsdefself.included(base)base.before_filt