草庐IT

skip-active-record

全部标签

ruby-on-rails - rails : Active Admin Association Image column

我是ruby​​onrails的新手,刚刚安装了activeadmin并尝试自定义观看次数。我有一个产品和图像表。每张图片属于一个产品。现在我想在显示产品页面时显示一个带有相关图像的列。目前只有image_url文本不起作用。稍后我想做让图片以50x50px显示。我该怎么做?(图片模型:名称:字符串image_url:文本)这是我所做的:ActiveAdmin.registerProductdoindexdocolumn"Image"do|image|image.image_urlendcolumn:namecolumn:preview_textcolumn:full_textcolu

ruby-on-rails - rails 4 : Skip callback

我的应用程序中有拍卖和出价对象,当有人按下BIDBUTTON时,它会调用创建出价的BIDCREATEController,然后执行拍卖品上的一些其他东西:投标Controller->创建@auction.endtime+=@auction.auctiontimer@auction.winner=@auction.arewinning@auction.save拍卖模型before_update:set_endtimedefset_endtimeself.endtime=self.starttime+self.auctiontimerend所以问题是:在这个特定的@auction.save

ruby - 时间 :Class after requiring active_support/time_with_zone 的未定义方法 `zone`

我在使用Ruby2.2.1并安装了active_support4.2,所以我想使用Time.zone.parse('2007-02-1015:30:45')如此处所述:http://api.rubyonrails.org/classes/ActiveSupport/TimeWithZone.html但即使在需要active_support和active_support/time_with_zone之后,我觉得Time.zone仍然不起作用。观察:2.2.1:002>require"active_support"=>true2.2.1:003>Time.zoneNoMethodError

ruby - Rspec any_instance.stub 为 nil :NilClass exception 引发未定义的方法 `any_instance_recorder_for'

这是我正在测试的包含在Foo.rb中的类:classFoodefbarreturn2endend这是Foo_spec.rb中包含的我的测试:require"./Foo.rb"describe"Foo"dobefore(:all)doputs"#{Foo==nil}"Foo.any_instance.stub(:bar).and_return(1)endit"shouldpassthis"dof=Foo.newf.bar.shouldeq1endend我得到以下输出:falseFFailures:1)FooShouldpassthisFailure/Error:Foo.any_insta

ruby-on-rails - 为什么都是autoload,load_all!并要求全部用于 active_support.rb?

我正在查看active_support.rb以尝试了解它使用的加载过程。它使用三种加载方法:load_all!、autoload和require。为什么在同一个文件中使用三种不同的加载方式?moduleActiveSupportdefself.load_all![Dependencies,Deprecation,Gzip,MessageVerifier,Multibyte,SecureRandom,TimeWithZone]endautoload:BacktraceCleaner,'active_support/backtrace_cleaner'autoload:Base64,'ac

ruby - 使用 RVM 使用 sinatra 应用程序加载 Active Record gem 时出错

我为我正在启动的sinatra应用程序设置了一个项目级RVMgemset,它将使用ActiveRecord连接到本地数据库。为了测试它,我尝试运行以下测试应用程序:测试.rbrequire'rubygems'#maynotbeneeded,dependingonplatformrequire'sinatra'require'activerecord'classArticle"sqlite3",:database=>"hw.db")Test.first.contentend(摘自这个问题的答案:What'sthebestwaytotalktoadatabasewhileusingSina

ruby-on-rails - 如何获取 Active Storage 图像的 url

我想通过api获取带有附加图像的记录列表作为链接或文件。我有一个简单的模型:classCategory下一步行动:defindex@categories=Category.all.with_attached_imagerenderjson:@categories.to_json(include:{image_attachment:{include::blob}})end这是我获得图像对象的唯一方法。我看到下一个结果:{"id":4,"name":"Cat1","description":""},{"id":1,"name":"Cat2","description":"","image_

ruby-on-rails - Rails 3 做 skip_before_filter 的方法,:only

在rails2.8中我们可以这样写skip_before_filterskip_before_filter:require_login,:only=>[:create,:new,:accept]这意味着,我只想将过滤器require_login应用于这些操作[:create,:new,:accept],并跳过其他操作的过滤器。不过好像,这条路是deprecated在rails3中。和新的skip_filter被添加。我试过了skip_filter:require_login,:only=>[:create,:new,:accept]但它不起作用,所以我如何在Rails3中执行此操作。

ruby - 您如何处理 Active Admin 资源中的序列化编辑字段?

我有一个模型,Domain,它有一个文本字段,names。>railsgmodelDomainnames:textinvokeactive_recordcreatedb/migrate/20111117233221_create_domains.rbcreateapp/models/domain.rb>rakedb:migrate==CreateDomains:migrating==================================================--create_table(:domains)->0.0015s==CreateDomains:migrat

ruby - 配置Active Admin的标签has_many

好吧,我有两个与一对多关联相关的模型。#models/outline.rbclassOutlinetruef.input:pages,:required=>true...f.buttonsendf.inputs"DocumentVersions"dof.has_many:documents,:name=>"DocumentVersions"do|d|d.input:file,:as=>:filed.buttonsdod.commit_button:title=>"AddnewDocumentVersion"endendendendend正如您在admin/outlines.rb中看到的