草庐IT

New_actions

全部标签

ruby-on-rails - 什么是 :domain symbol referring to when configuring action mailer?

Appname::Application.configuredoconfig.action_mailer.delivery_method=:smtp#typicalsmtp_settingsforgmailaccountconfig.action_mailer.smtp_settings={:address=>"smtp.gmail.com",:port=>587,:domain=>"domain.of.sender.net",:authentication=>"plain":user_name=>"spencecooley":password=>"secret":enable_sta

ruby-on-rails - `new` 关键字在此 Ruby 方法定义中如何工作?

Railscasts发布了一个关于重构的精彩片段。一种方法是将复杂的Controller逻辑移动到服务对象中,而不是将其下推到模型中。在oneserviceobject,使用了以下代码:classPasswordResetattr_reader:userdefself.from_email(email)newUser.find_by_email(email)enddefself.from_token(token)newUser.find_by_password_reset_token!(token)end...endnew关键字在两个方法体中起什么作用?新的User.find_by_。

ruby-on-rails - Ruby:Class.new 在 Rails 控制台中给出 "Class not initialized"错误

我正在创建一个轻量级应用程序来创建和显示即将发生的事件的信息。我定义了一个Event类,它将args散列作为参数。初始化方法定义如下。classEvent到目前为止,还不错。然后,在Rails控制台中,我定义了一个args散列并尝试创建一个Event实例,但出现以下错误。[4]pry(main)>args={what:'what',theme:'theme'}=>{:what=>"what",:theme=>"theme"}[5]pry(main)>Event.new(args)=>#这看起来很简单,但我很难理解。任何帮助表示赞赏。 最佳答案

轨道上的 ruby : How to create table for a new model

我用railsgeneratemodelmynewmodelstring:namestring:description生成一个新模型。如何将这个新模型部署到我的开发数据库中?我的sqlite数据库中已经有一堆数据库。我试过了rakedb:migrate在db中生成这个新表似乎有问题。更新:添加了错误信息==CreateMynewmodels:migrating===============================================--create_table(:mynewmodels)rakeaborted!Anerrorhasoccurred,thisandal

ruby - "Hash.new(0)"和 "{}"有什么区别

我的代码出现了(对我而言)意外行为,因此我尝试在REPL中隔离问题。然而,这些构造函数似乎都具有相同的结果(空散列):irb>a={}#=>{}irb>b=Hash.new(0)#=>{}不过,当我将{}传递给reduce函数时,我得到了一个NoMethodError。这两个构造函数有什么区别?irb>arr="counttheoccuranceofeachofthewords".scan(/\w+/)#=>["count","the","occurance","of","each","of","the","words"]irb>x=arr.reduce(Hash.new(0)){|h

ruby-on-rails - Rails 上的 ruby : How to have multiple submit buttons going to different methods (maybe with with_action? )

这个问题在这里已经有了答案:HowdoIcreatemultiplesubmitbuttonsforthesameforminRails?(7个答案)关闭9年前。所以..'save'%>'library'%>然后在我的Controller中:with_actiondo|a|a.savedoenda.librarydoendend问题是只有一个操作被调用...两个submit_tags调用相同的操作...知道为什么吗?或者我如何获得两个按钮以将表单提交给两种不同的方法?

ruby-on-rails - 如何在测试 Action 时将值放入闪存中

我正在尝试测试需要将值存储在闪存中的操作。defmy_actionifflash[:something].nil?redirect_toroot_pathifflash[:something]returnend#Dosomeotherstuffend在我的测试中,我做了类似的事情:before(:each)doflash[:something]="bob"endit"shoulddowhateverIhadcommentedoutabove"doget:my_action#Assertsomethingend我遇到的问题是flash在my_action中没有值。我猜这是因为实际上没有请

ruby-on-rails - rails : Where does new_*something*_path variable get set up?

我为“消息”创建了一个脚手架,并且new_message_path和edit_message_path(用于link_to's)都已设置,但现在我已经创建了app/views/messages/sent.html.erb,我想做类似的内容,但我不知道该怎么做。我明白了undefinedlocalvariableormethod`sent_message_path'for# 最佳答案 这些方法是在定义路由时自动创建的,对于RESTful路由,它们遵循可预测的约定。运行“rakeroutes”是查看生成的所有路由的有用方法。我建议您阅读

ruby-on-rails - RoR 'new' 命令挂起

我刚刚开始使用ruby​​onrails。在终端中,我输入了“railsnewTestApp”,这是终端发生的事情:createcreateREADMEcreateRakefilecreateconfig.rucreate.gitignorecreateGemfilecreateappcreateapp/assets/images/rails.pngcreateapp/assets/javascripts/application.jscreateapp/assets/stylesheets/application.csscreateapp/controllers/application

ruby-on-rails - ruby on rails 中的 Controller 和 Action 有什么区别?

谁能告诉我ruby​​onrails中Controller和Action之间的区别?我从官方Rails指南中获取了这个定义:Acontroller'spurposeistoreceivespecificrequestsfortheapplication.Routingdecideswhichcontrollerreceiveswhichrequests.Often,thereismorethanoneroutetoeachcontroller,anddifferentroutescanbeservedbydifferentactions.Eachaction'spurposeistoc