草庐IT

ember-controllers

全部标签

ruby-on-rails - 使用 ApplicationController.renderer.render 从 Controller 外部渲染的 Rails 5 不会在自身上设置变量

我正在使用Rails5ApplicationController.renderer.render方法从模型中进行渲染。我需要将一些变量传递给我的布局,这是我使用locals选项完成的;如果直接访问此变量,则该变量在布局中可用,但不能通过self访问。这是我设置渲染的方式html_string=ApplicationController.renderer.render(file:"/#{template_path}/base/show",:formats=>[:pdf,:html],locals:{:@routing_form=>self,:controller_name=>contro

ruby-on-rails - rails : How can you access session variables using multiple controllers?

我在使用session变量时遇到问题。我有两个名为“graduate_students_controller”和“current_students_controller”的Controller。这些Controller中的每一个都控制不同的View文件。我在这两个Controller中使用session变量来存储session信息。问题来了。假设我有两个View文件“reports/current_students_list”、“reports/graduate_students_list”,每个文件都由上述Controller单独控制。现在,如果我尝试从同一浏览器中打开这两个网页并尝

ruby-on-rails - Rails Controller 操作是否隐式定义事务绑定(bind)?

给定以下代码:defcreate@something=Something.new(params[:something])thing=@something.thing#anothermodel#modificationofattributesonboth'something'and'thing'omitted#doIneedtowrapitinsideatransactionblock?@something.savething.saveendcreate方法是隐式包装在ActiveRecord事务中,还是需要将其包装到事务block中?如果我确实需要包装它,这是最好的方法吗?

ruby-on-rails - rails : Pass Parameters to New Controller during 'redirect_to'

我正在使用RyanBates的RailsCastonWickedWizardForms创建一个多步骤表单。我没有定义current_user方法(不使用身份验证gem)-因此,我试图在redirect_to期间传递user.id参数-不幸的是,我似乎无法让它工作。任何帮助表示赞赏!我的用户Controller创建方法defcreate@user=User.new(params[:user])respond_todo|format|if@user.saveformat.html{redirect_tocontroller:'user_steps',id:'user.id'}#format

ruby-on-rails - 为什么 Controller 操作应该调用一个模型方法而不是初始查找或新方法?

我的模型中的函数几乎包含所有“共享”语句。问题是,当我需要在我的Controller中使用多个功能时,出现以下错误:ControlleractionshouldcallonemodelmethodotherthananinitialfindornewIDE会更深入地解释:Thisinspectionwarnsifacontrolleractioncontainsmorethanonemodelmethodcall,aftertheinitial.findor.new.It’srecommendedthatyouimplementallbusinesslogicinsidethemode

ruby-on-rails - 如何访问设计 token 授权注册 Controller ?

我正在使用Deviseauthtokengem用于验证我的Rails应用程序的某些部分。但是,当我尝试使用注册路径创建新用户时,出现以下错误{"errors":["Authorizedusersonly."]}。这是我用于测试的rspec代码,it'createsauserusingemail/passwordcombo'dopostapi_user_registration_path,{email:'xxx',password:'yyy',password_confirmation:'yyy'}putslast_response.bodyexpect(last_response.bo

ruby-on-rails - Rails 5 升级 :/actionpack-5. 0.0/lib/action_controller/test_case.rb:49:in `initialize':参数数量错误(0 代表 2)(ArgumentError)

我最近正在进行Rails5升级,当我尝试启动Rails控制台时遇到了这个错误:/actionpack-5.0.0/lib/action_controller/test_case.rb:49:ininitialize':wrongnumberofarguments(0for2)(ArgumentError)当前bundleupdaterails已经完成了gem依赖项的解决,足以更新到5.0.0,rspec正在运行(尽管我正在修复很多中断)。我也可以运行railss没有错误。这里是代码中断行:https://github.com/rails/rails/blob/master/action

ruby-on-rails - 在 SASS 中访问 Ruby 变量(从模型或 Controller )

有没有办法在SASS中访问Ruby变量,还是我必须为它创建一个自定义函数?我想做的是为每个用户生成一个样式表,所以在Controller中,我会做类似的事情:defshowrespond_todo|format|format.css{render:partial=>"styles"}endend然后在View名称_styles.haml中我这样做::sass#header:backgroundurl(user.banner.url)这可能吗?*显然不是:http://sass-lang.com/docs/yardoc/file.FAQ.html#q-ruby-code除了我们所做的这个

ruby-on-rails - 使用 Rails 编写 RSpec 测试时,spec/requests 文件夹和 spec/controllers 应该放什么?

我对Rails还很陌生,并试图通过从一开始就实现测试来以“正确”的方式做事。昨天我使用脚手架生成器创建了我的第一个模型/View/Controller配置。虽然有人告诉我您真的不应该使用脚手架,但它很有用,因为我可以了解Rails代码的结构。我注意到的一件事是,自动生成的RSpec大部分放在spec/controllers文件夹中。然而当我看到thisepisodeofRailscasts,我注意到他用了railsgenerateintegration_test[test_name]将单个测试文件放入spec/requests文件夹的命令。然而,他编写的所有测试都与Controller

ruby-on-rails - Rails Controller 中未定义的方法呈现 - 尝试使用 200 状态代码响应 Sendgrid

我正在使用SendgridParseAPI和Griddlergem来接受传入的电子邮件。在大多数情况下,这工作正常;但是,如果您未使用状态代码200响应Sendgrid,他们将假定该应用程序未正确接收POST请求并继续尝试进行POST3天。我正在尝试使用状态代码进行响应,但遇到了问题。在常规的RESTful路由中,您可以执行类似...render:status=>200但是,我认为这必须在Controller中完成才能识别渲染方法。Griddler建议您创建一个EmailProcessor模型并使用“处理”方法来处理电子邮件。据我了解,您不能在模型中使用渲染方法。因此,我使用类方法创建