jjzjj

user_controller

全部标签

ruby-on-rails - 重定向 Rails 3 中特定 Controller 的记录器输出

我们想要一个Controller集合,我们将所有操作和下游方法的记录器输出路由到一个单独的日志文件。这是一个Rails3项目。在Rails2中,我们通过重新定义“logger”方法来做到这一点,但在Rails3中,记录的方式是使用“Rails.logger”。我试着把Rails::logger=Logger.new(File.join(Rails.root,'log',"reports_controller.log"),10,1000000)在Controller的顶部,但只有在操作中专门使用Rails.logger的特定情况才会发送到指定的日志文件,Controller的所有默认日志

ruby-on-rails - after_save 回调将 updated_by 列设置为 current_user

我想使用after_save回调将updated_by列设置为current_user。但是current_user在模型中不可用。我应该怎么做? 最佳答案 需要在controller中处理。首先在模型上执行保存,然后如果成功则更新记录字段。例子classMyController另一种选择(我更喜欢这个)是在您的模型中创建一个自定义方法来包装逻辑。例如classRecord 关于ruby-on-rails-after_save回调将updated_by列设置为current_user,我

ruby-on-rails - 我可以在没有 Controller 的情况下直接从 routes.rb 渲染布局吗?

我想为网站的管理和公共(public)部分设置一对样式指南。每个都需要自己的布局,其中包含静态html和调用erbpartials的混合(因此静态页面不会削减它)。我不需要Controller来为这些页面提供服务,而且我不希望有效的仅开发内容使其余代码困惑。这让我想知道是否有一种方法可以直接呈现布局。免责声明:我明白这不是我应该经常/永远做的事情,而且我知道有很多争论可以解释为什么这是一个坏主意。我对这是否可能感兴趣。有没有办法让我直接从routes.rb渲染布局而不通过Controller? 最佳答案 出于某种奇怪的原因,我想暂时

ruby-on-rails - "554 Please activate your Mailgun account. Check your inbox or log in to your control panel to resend the activation email."错误 Ruby on Rails

我正在使用RubyonRails构建网络应用程序。我正在使用Mailgun作为这个应用程序的邮件程序。当我使用Facebook注册时它工作正常但是当我尝试使用电子邮件和密码注册时,我不断收到此错误“554请激活您的Mailgun帐户。检查您的收件箱或登录到您的控制面板以重新发送激活电子邮件。“我已经在mailgun仪表板中将eamil授权给授权收件人。这是我的代码:Registrations_controller.rbclassRegistrationsControllerconfig/environments/development.rbRails.application.confi

ruby - Heroku,设计 : Getting 'NoMethodError (undefined method ` to_key' for :user:Symbol)'

我不知道它是什么时候发生的,但我收到了这个错误NoMethodError(undefinedmethod'to_key'for:user:Symbol)此行为仅发生在HerokuCedar堆栈上。我使用Devise(1.4.2)通过FacebookonRails3.1.0.rc6和ruby​​1.9.2-p290进行身份验证。它发生在sign_in_and_redirect(:user,authentication.user)行。这是我的方法:defcreateomniauth=request.env['omniauth.auth']authentication=Authenticat

ruby-on-rails - 如何为模型/ View / Controller 以外的文件编写/运行规范

当我对模型/View/Controller使用railsgenerate命令时,使用rails和rspec很容易让rspec为我生成必要的文件。但是现在我想为我编写的模块编写规范。该模块位于/lib/my_module.rb中,因此我在/spec/lib/my_module_spec.rb中创建了一个规范我遇到的问题是,当我尝试执行rspecspec/时,文件my_module_spec.rb已运行,但在中引用了我的模块找不到lib/my_module.rb。执行此操作的正确方法是什么?仅供引用,my_module_spec.rb文件中已经包含require'spec_helper'r

ruby-on-rails - 设计 Controller 如何改变布局?

这个问题在这里已经有了答案:differentlayoutforsign_inactionindevise(8个答案)关闭7年前。如何更改设计Controller中的布局?

ruby-on-rails - routes.rb - 不支持 Controller 名称

我遇到了一个很奇怪的问题。这是与routes.rb相关的部分:resources:playersmatch'/players/:userid',:to=>'Players#show'当您访问localhost:3000/players/1234时出现此错误:'Players'isnotasupportedcontrollername.Thiscanleadtopotentialroutingproblems.Controller中的相关代码:defshowbeginifPlayer.find_by(:uid=>:userid)then@playerattributes=Player.f

ruby-on-rails - Rails 4.2 Action Controller :BadRequest custom error message

如果验证失败或参数丢失,我想从我的Controller返回400-错误请求。所以在我的Controller中如果有ifparams["patch"].nil?thenraiseActionController::BadRequest.new("TheJsonbodyneedstobewrappedinsidea\"Patch\"key")end我在我的应用程序Controller中发现了这个错误:rescue_fromActionController::BadRequest,with::bad_requestdefbad_request(exception)renderstatus:4

ruby-on-rails - 动态生成一个 `link_to` 到 Controller Action `edit`

我正在使用RubyonRails3.0.7,我想生成一个link_to到Controller操作edit,动态。我必须在部分模板中使用它,但问题是我正在为不同的模型数据呈现相同的部分模板(也就是说,我在其中传递了不同类实例的局部变量)。所以我不能使用路由“神奇的RoR方式”`edit__path()`.我想做如下的东西:link_to(@resource_class_instance,:action=>'edit')#Thisexampleiswrong,butitsuggeststheidea这可能吗?如果是这样,我该怎么做? 最佳答案