这是我在rake任务中打开文件的代码:
File.open(Rails.root.join("public/system/xmls/**/original/*.csv"),"r") do |file|
#etc
Run Code Online (Sandbox Code Playgroud)
但它不匹配任何文件(有三种可能的匹配).第一个**是一个名为2位的文件夹.我哪里错了?
什么是明智的说法.
if @thing == "01" or "02" or "03" or "04" or "05"
Run Code Online (Sandbox Code Playgroud)
(这些数字包含在数据类型字符串列中.)
请将数据与框匹配.以下是heroku config在我闪亮的新专用数据库上运行的(doctored)结果:
=== Config Vars for myapp
DATABASE_URL: postgres://thinga:thingb@ec2-23-21-119-36.compute-1.amazonaws.com:5432/thingc
GEM_PATH: vendor/bundle/ruby/1.9.1
HEROKU_POSTGRESQL_OLIVE_URL: postgres://thinga:thingb@ec2-23-21-119-36.compute-1.amazonaws.com:5432/thingc
HIREFIREAPP_TOKEN: 7965994a31ace96fc5f390longtoken
LANG: en_US.UTF-8
MEMCACHE_PASSWORD: password
MEMCACHE_SERVERS: mc9.ec2.northscale.net
MEMCACHE_USERNAME: myapp%40heroku.com
PATH: vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin:bin
PGBACKUPS_URL: https://thing@pgbackups.heroku.com/client
RACK_ENV: production
RAILS_ENV: production
Run Code Online (Sandbox Code Playgroud)
在我的本地PGAdmin3上配置新服务器的字段是:
Name
Host
Port
Service
Maintenance DB
Username
Password
Group
Run Code Online (Sandbox Code Playgroud)
怎么回事?
我有一个非用户友好的验证错误消息,我想覆盖它:
Cannot delete record because dependent [unfriendly model names] exist
Run Code Online (Sandbox Code Playgroud)
协会在哪里
has_many :unfriendly_model_names, dependent: :restrict_with_error
Run Code Online (Sandbox Code Playgroud)
我希望它是
Cannot delete record because dependent [nice readable model names] exist
Run Code Online (Sandbox Code Playgroud)
我希望我可以使用 I18n,但是我如何以及在什么时候将更友好的字符串传递给record插值?
en-GB:
activerecord:
errors:
messages:
restrict_dependent_destroy:
has_many: "Cannot delete record because dependent %{record} exist"
Run Code Online (Sandbox Code Playgroud) 你如何使用Formtastic单独编辑多个记录来完成RyanB的Railscast所涵盖的内容?Formtastic不使用form_tag,RyanB的方法依赖于form_tag.
这个:
- book.prices.order(:currency_code).each do |price|
Run Code Online (Sandbox Code Playgroud)
按货币代码按字母顺序返回所有书籍的价格:
AUD 19.99
GBP 9.99
NZD 26.00
USD 14.95
Run Code Online (Sandbox Code Playgroud)
现在,我怎么能巧妙地让GBP始终出现在列表的顶部,其他人按字母顺序排序,如下所示:
GBP 9.99
AUD 19.99
NZD 26.00
USD 14.95
Run Code Online (Sandbox Code Playgroud)
这个答案显示了SQL解决方案,但我不确定Rails的方式.
你可以在包含WickedWizard gem的控制器中使用非restful方法吗?
控制器:
class Books::BookUpdateController < ApplicationController
include Wicked::Wizard
steps :title_step, :ai_archive_step, :ai_override_step #etc
def show
...
end
def update
...
end
def waterfall
...# loads of code to set up instance variables in the view, which I don't want to have to include in the normal show action for all the wizard steps.
end
end
Run Code Online (Sandbox Code Playgroud)
路线:
resources :book_update do
member do
get 'waterfall'
... and others
end
end
Run Code Online (Sandbox Code Playgroud)
gem的版本1和更低版本允许非静态操作,但是这个解决此PR的提交强制执行步骤名称.我去这条路线的错误 http://localhost:3000/book_update/3949/waterfall是
Wicked::Wizard::InvalidStepError in Books::BookUpdateController#waterfall …Run Code Online (Sandbox Code Playgroud) 我试图将一些模型代码移动到一个模块.
原始模型方法:
我试图将一些模型代码移动到一个模块.
原始模型方法:
class Book < ActiveRecord::Base
def book_royalty(period='enddate', basis="Net receipts")
#stuff
end
end
Run Code Online (Sandbox Code Playgroud)
所以我补充一下
include Calculation
Run Code Online (Sandbox Code Playgroud)
并将方法移动到模块:
module Calculation
def book_royalty(period='enddate', basis="Net receipts")
#stuff
end
end
Run Code Online (Sandbox Code Playgroud)
但现在我得到了
错误的参数数量(2表示0)
如果我在book.rb模型中创建一个类方法,即如果我创建方法名称,那么这也是我得到的错误self.book_royalty(args).
我无意中将方法转移到模块类方法?我include在book.rb中使用,不是extend.如何让父模型成功包含模块的方法?
book_royalty 在Royaltystatement模型中调用.
book.rb:
attr_accessor :book_royalty
Run Code Online (Sandbox Code Playgroud)
royaltystatement.rb:
def initialize_arrays
@royalty = []
...
end
def sum_at_book_level(contract)
contract.books.where(:exclude_from_royalty_calc => false).each do |book|
book.book_royalty("enddate", basis)
@royalty.push(book.book_royalty("enddate", basis))
# etc
end
Run Code Online (Sandbox Code Playgroud) 我正在使用active_record fork(link)来使用delayed_job .
在控制器中:
guide = Rightsguide.new
guide.run(@works, current_user)
Run Code Online (Sandbox Code Playgroud)
在Rightsguide ruby类中:
require 'delayed_job'
require 'delayed/tasks'
require 'prawn'
require 'open-uri'
class Runrightsguide
def run(works, current_user)
pdf = Rightsguidereport.new(works, current_user)
filename = "#{Rails.root}/public/#{Date.today}_rightsguide.pdf"
pdf.render_file(filename)
pdf_file = File.open(filename)
archive = RightsguideArchive.new(:user_id => current_user)
archive.pdf = pdf_file
archive.save!
User.find(current_user).notice "<a href='/rightsguide_archives' target='_blank'>View Rights Guide</a>", :level => :notice, :sticky => true, :title => "AIs generated."
end
end
Run Code Online (Sandbox Code Playgroud)
以上工作正常,但是当我使用其中一个delayed_job调用时,例如handle_asynchronously :run在run我得到的方法之后wrong number of arguments (2 for 1).
ruby ×3
api ×1
delayed-job ×1
file ×1
forms ×1
formtastic ×1
heroku ×1
module ×1
params ×1
pgadmin ×1
postgresql ×1
rails-i18n ×1
rest ×1
wicked-gem ×1
wildcard ×1