Tag: ruby on rails 3

RailsTutorial 3.2 Ch 9 – “before {valid_signin(user)}”导致RSpec测试失败

我目前在RailsTutorial 3.2, 第9.3.1节用户索引中 。 代码清单9.27指向spec/requests/authentication_pages_spec.rb代码的编辑,如下所示: require ‘spec_helper’ describe “Authentication” do . . . describe “with valid information” do let(:user) { FactoryGirl.create(:user) } before { valid_signin(user) } it { should have_selector(‘title’, text: user.name) } it { should have_link(‘Users’, href: users_path) } it { should have_link(‘Profile’, href: user_path(user)) } it { should have_link(‘Settings’, href: edit_user_path(user)) } it […]

发出AJAX请求转到正确的URL

我在一些jquery代码中有自动完成的这个ajax请求: $.ajax({type:”POST”, url:(“showable_videos/create.js”), data:{video:{profile:val}}}); 自动填充function会作用于我的video节目视图中的字段。 因此,当它发出AJAX请求时,我收到此错误: Started POST “/videos/showable_videos/create.js” for 127.0.0.1 at Tue Apr 26 00:18:33 -0700 2011 ActionController::RoutingError (No route matches “/videos/showable_videos/create.js”): 当我希望它只是/showable_videos/create.js时,Rails会在URL之前添加/videos/ 。 我怎样才能解决这个问题?

消息控制器中未定义的方法`stringify_keys’

当我尝试提交表单时出现以下错误(当1个用户想要向另一个用户发送消息时,表单会显示) NoMethodError in MessagesController#create undefined method `stringify_keys’ for “”:String Rails.root: /Users/fkhalid2008/loand Application Trace | Framework Trace | Full Trace app/controllers/messages_controller.rb:31:in `new’ app/controllers/messages_controller.rb:31:in `create’ 以下是消息控制器的相关代码: def new @message = Message.new if params[:reply_to] @reply_to = @user.received_messages.find(params[:reply_to]) unless @reply_to.nil? @message.to = @reply_to.sender.login @message.subject = “Re: #{@reply_to.subject}” @message.body = “\n\n*Original message*\n\n #{@reply_to.body}” end end end def create @message = […]

创建用于删除属于产品的上传的表单

我使用基于此应用程序https://github.com/websymphony/Rails3-Paperclip-Uploadify的回形针进行了多次上传,并且它工作正常,但现在我需要构建一个表单,用户可以删除部分上传内容。 我有这个表格来删除一个产品的上传 { :method => :put }, :html => { :multipart => true } do |f| %> ‘checkbox’ %> Delete item 这个表单以某种方式显示正确的上传号码,我可以在终端窗口中看到所有上传产品都带有product_id = product.id,但是我没有在页面中显示图像,如图所示: 终奌站 Started GET “/admin/products/40” for 127.0.0.1 at Tue Apr 10 10:20:06 +0300 2012 Processing by Admin::ProductsController#show as HTML Parameters: {“id”=>”40”} Creating scope :page. Overwriting existing method AdminUser.page. AdminUser Load (2.4ms) SELECT […]

如何访问rails中belongs_to关联中的字段

我正在使用具有用户和授权模型的rails应用程序。 Eacch用户可以拥有多个授权,每个授权都属于特定用户。 我为此使用了belongs_to协会。 现在当我试图访问特定用户的授权使用时 user = User.find(params(:id)) auth = user.authorizations 现在的问题是当我尝试使用授权访问字段时 auth.id 我没有找到方法发现错误,但以下 Authorization.first.id 工作良好。 他们之间有什么区别?

计算运行总轨数3

在Rails中计算运行总计的最佳方法 – 或者实际上是什么方式 – 是什么? 我有一个模特,Sale。 它有一个数量列和一个sales_value列。 当表按isbn_id排序,然后是channel_id,然后是invoice_date时,我需要填充第三列,total_quantity,以及先前记录的数量值的总和。 这设置了各种合理的数据库管理警报响铃,所以我想知道它是否可能。 需要此累积金额的原因是对累计数量在特定范围内的销售额应用百分比。 我不能在所有记录中使用平均销售价值,因为销售利润率会随着时间的推移而发生显着变化 – 因此我会将平均值应用于可能超过或低于特许权使用费收入者的一堆销售额。 所以。 我应该在Sale模型上执行before_save回调,并以某种方式执行update_attribute吗? 当表以特定方式排序时,是否有一种方法可以返回上一条记录的值? 或者我应该将所有Sale记录转储到一个数组中,并且可能使用inject来累积运行总计? 任何想法最受欢迎,提前感谢。 更新: 此处询问后续问题。

每当我在我的Rails 4.2.1应用程序中单击使用Payola-Payment Gem(为Stripe制作的gem)付款时,我都会收到“待定错误”

使用Payola-Payments Gem处理Stripe Payments,有必要为您的交易设置后台工作程序。 使用ActiveJob设置后台工作程序后,单击付款时会出现错误。 这是它 : 注意:我使用的是Windows环境(Windows 8),我相信这里有些问题。 我的视图上的错误警报渲染: 这似乎花了太长时间。 请联系支持并给他们交易ID:ook4dp 以下是Console生成的代码 Started POST “/payola/buy/job/excelwithcode-7d492bf330ab66b0eaa61ce2ce277e14” for 127.0.0.1 at 2016-04-25 20:50:26 +0100 Processing by Payola::TransactionsController#create as */* Parameters: {“stripeToken”=>”tok_184FksCc1zXXaitaOrD5ELaH”, “stripeEmail”=>”neededforpayments@mybusinesstest.com”, “authenticity_token”=>”Uod7Ue4XHNcCvayA6G1shiiI43QKoBOrbImnwt0TGFHVlp11WdHaNTcPl/0UyYefcT6foowc30bFdtK0cJuXog==”, “product_class”=>”job”, “permalink”=>”excelwithcode-7d492bf330ab66b0eaa61ce2ce277e14”} Payola::Affiliate Load (1.0ms) SELECT “payola_affiliates”.* FROM “payola_affiliates” WHERE (lower(code) = lower(NULL)) ORDER BY “payola_affiliates”.”id” ASC LIMIT 1 Job Load (1.0ms) SELECT “jobs”.* FROM […]

在不同环境中,表的延迟作业选择属性不同

我正在使用延迟作业将Model方法排队在另一个Model如下所示: article_loader.rb date_value_in_string = “2017-06-21 07:17:00” Article.delay(:queue => ‘article_load’).article_loading([date_value_in_string]) 即使我已经将String作为参数传递给方法,但在方法内部它会在生产环境中转换为Time对象。 article.rb在生产环境中 def self.article_loading(args) date_value = args[0] p date_value.class # Time end 在开发环境中,它是一个字符串。 article.rb在开发环境中 def self.article_loading(args) date_value = args[0] p date_value.class # String end 我不知道为什么会这样。 任何帮助将不胜感激。

关系=>通过polymorphic_path?

我的模特是: class City < ActiveRecord::Base belongs_to :region has_many :activities has_many :restaurants end class Activity < ActiveRecord::Base belongs_to :city end 我想访问所有城市的所有活动。 从上一个关于stackoverflow的问题,我读到我不能这样做@ cities.activities,而是我做了以下事情: 通过与Region的关联添加has_many class Region :cities end @activities = @region.activities.find_all_by_homepage_city(true) 但是当我调用变量@activities时,请使用polymorphic_path。 – @activities.each do |b| %li =link_to b.name, polymorphic_path([@region, @city, b]) 我收到消息“not region for region_activity_path”。 这是正确的,因为没有资源:资源之后的活动:区域 resources :regions do resources :cities do resources :activities 我可以在区域之后添加活动资源,但后来我的url不正确。 […]

Rails 3路由如何匹配多个?

如何匹配多个控制器,例如id? 我在我的路线上试过这个: match ‘/:id’ => ‘kategoris#show’ match ‘/:id’ => ‘tags#show’