草庐IT

gitlab_rails

全部标签

ruby - 在没有 rails 的 ruby​​ 中实现一个 rails before_filter

我在所有类(class)中都使用galogger。我希望每个消息都以类名和方法名开头,如下所示:Class_name::Method_name这就是我现在正在做的:classFOOdefinitializeenddefbarmsg_prefix="#{self.class}::#{__method__}"...somecode...@logeer="#{msg_prefix}msg..."enddefbar2msg_prefix="#{self.class}::#{__method__}"...somecode2...@logeer="#{msg_prefix}msg2..."ende

ruby-on-rails - Rubyzip:将 zip 文件直接导出到 S3 而无需将 tmpfile 写入磁盘?

我有这段代码,它将一个zip文件写入磁盘,读回,上传到s3,然后删除文件:compressed_file=some_temp_pathZip::ZipOutputStream.open(compressed_file)do|zos|some_file_list.eachdo|file|zos.put_next_entry(file.some_title)zos.printIO.read(file.path)endend#Writezipfiles3=Aws::S3.new(S3_KEY,S3_SECRET)bucket=Aws::S3::Bucket.create(s3,S3_BUCK

ruby-on-rails - Rails 语法错误 : unexpected keyword_ensure, 期望输入结束

我是Rails的新手,我尝试根据教程创建一个论坛应用程序。这是我的论坛页面,但我一直收到错误消息:syntaxerror,unexpectedkeyword_ensure,expectingend-of-inputExtractedsource(aroundline#33):3031这是抛出错误的论坛索引页面:ForumLastPosttopicsagobynoposts-->'Areyousure?',:method=>:delete%> 最佳答案 -->这是在做什么?一个html注释的ERB标签仍然会评估。去掉它。如果您想评论r

ruby-on-rails - 如何在 Rails 中编写和包含常规 ruby​​ 类

我正在学习Rails。我有一个Controller负责呈现来自用户上传的解析文件的数据。我不希望将数据存储在模型中的任何位置。我可以包含一个可以在我的Controller方法中实例化的类吗?这是我的意思的基本代码示例:这个Controller只包含一个方法:classMyController这是在实例化调用其方法时处理逻辑的类:classFileProcessorServicedeftestreturn'Thisisatest'endend我的问题:存放这个类的最佳位置在哪里?我怎样才能在我的Controller中引用这个类?关于在Rails中使用类这个特定主题的任何建议?常规ruby

ruby-on-rails - Activeadmin 渲染 'new' 在尝试覆盖创建 Controller 方法时给出无法找到没有 ID 的用户

我正在尝试在activeadmin中创建一个页面,用户可以在其中创建新的用户帐户。我正在使用以下代码覆盖我的用户模型的默认创建方法。当我尝试呈现new页面时,出现错误Couldn'tfindUserwithoutanID。为什么在尝试重新呈现new操作时会出现此错误?ActiveAdmin.registerUserdopermit_paramsdopermitted=[:email,:encrypted_password]permitted日志:StartedGET"/admin/users/new"for127.0.0.1at2014-03-0921:34:35-0500Proces

ruby - Rails before_action for ActionMailer 将使用邮件程序参数

假设我有一个发送不同电子邮件的邮件程序,但预计会使用相同的参数调用。我想为所有邮件操作处理这些参数。因此,调用一个before_action来读取发送到邮件程序方法的参数/mailers/my_mailer.rbclassMyMailer然后在我的Controller/服务中我在某处做MyMailer.actionx(*mailer_params).deliver_now如何访问before_actionblock中的same_param参数列表?编辑:我想重构/mailers/my_mailer.rbclassMyMailer还有这个重构/mailers/my_mailer.rbcl

ruby-on-rails - Heroku 无法检测到 rake 任务(LoadError : cannot load such file -- rspec/core/rake_task)

我正在使用travisCI部署到heroku,但出现此错误。这才刚刚开始。我有基本的railsRakefile,我有一个看起来像这样的文件,否则travis无法检测到rake任务:#lib\tasks\spec.rakerequire'rspec/core/rake_task'RSpec::Core::RakeTask.newtask:default=>:spec为什么会专门为heroku显示此错误?编辑-我有一个与给出的(更好的)答案相似的版本:beginrequire'rspec/core/rake_task'desc"Runallexamples"RSpec::Core::Rak

ruby-on-rails - 在 Ruby 中验证 Google ID token 的完整性

我正在将Google登录功能集成到Rails驱动的站点。我正在按照https://developers.google.com/identity/sign-in/web/backend-auth上的指南进行操作,但我遇到了一些问题。主要挂断是验证IDtoken的完整性段落。它概述了验证JWT的几个步骤,然后指出:Ratherthanwritingyourowncodetoperformtheseverificationsteps,westronglyrecommendusingaGoogleAPIclientlibraryforyourplatform,orcallingourtoken

ruby - 是否有等效于 Rails `try` 函数的 Elixir?

在Rails中,您可以执行以下操作:@user.try(:contact_info).try(:phone_number)如果@user和contact_info都不为nil,则返回phone_number。如果其中之一为nil,则表达式将返回nil。我想知道在Elixir中最惯用的方法是什么,因为@user和contact_info是结构。 最佳答案 我认为一种方法是使用模式匹配,所以它会是这样的:caseuserdo%{contact_info:%{phone_number:phone_number}}whenphone_num

ruby-on-rails - 弃用警告 : Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s)

我将我的Rails5.1.4应用更新到了5.2.0。我的一个模型中有以下范围:scope:by_category,lambda{|category_slug|category_ids=Category.find_by(slug:category_slug)&.subtree_idswhere(category_id:category_ids)}由于该范围,Rails返回以下错误:DEPRECATIONWARNING:Dangerousquerymethod(methodwhoseargumentsareusedasrawSQL)calledwithnon-attributeargume