草庐IT

custom-formatting

全部标签

ruby-on-rails - 常量 Logger::Format not defined (NameError) with activerecord

当我在env.rb中需要'active_record'时,我遇到了错误constantLogger::Formatnotdefined(NameError)/usr/local/rvm/gems/ruby-1.9.3-p125@test/gems/activerecord-1.6.0/lib/active_record/support/clean_logger.rb:5:inremove_const'/usr/local/rvm/gems/ruby-1.9.3-p125@test/gems/activerecord-1.6.0/lib/active_record/support/cle

ruby-on-rails - 未应用 ActiveRecord cache_timestamp_format 配置

我正在尝试通过在application.rb或中设置此配置config.active_record.cache_timestamp_format=:nsec来更改迁移版本时间戳格式development.rb,就像这里所说的http://guides.rubyonrails.org/configuring.html#configuring-active-record.问题是这个配置被忽略了,不管我在那里设置的格式如何,当我生成一个新的迁移时,时间戳格式保持不变。我是不是做错了什么? 最佳答案 因为显然railsmigration忽略

ruby - respond_to only format.js 用于所有 mime 类型

我有一个响应于format.js的Controller,但是,大多数请求假设旧的format.html仍然存在并抛出404异常。如何捕获Controller上的所有MIME请求并将它们仅重定向到format.js?这是当前的ControllerActiondefsearchrespond_todo|format|unless@search.nil?format.js{render:partial=>'/search/search_form',:status=>200}elseformat.js{render:partial=>'/search/not_exist',:status=>5

ruby - Stripe 连接 : Charging an existing customer against a "connected" (Standalone) account

如果试图通过connectedaccount向客户记录(具有关联的信用卡)收费,我得到一个错误声明,“没有这样的客户:cus_xxxx”——尽管当不使用“已连接”帐户(通过平台账号)。例如,考虑以下Ruby代码,假设我们有一个ID为acct_ABC123的“已连接”(独立)帐户:#Usethe(secret)APIkeyforthe"platform"orbaseaccount.Stripe.api_key='sk_[...]'customer=Stripe::Customer.create(email:'customer@example.com')#Associateacredit-

ruby /事件记录 : custom sorting order

我正在开发一个Rails3.2ruby​​1.9.2项目。我从经典数据库中获取了一些值:designators=Model.find()我用(简化代码)显示它:">值例如:3L、3C、3R。(L代表左,C代表中心,4代表右)。我想要订购的值,例如:3L、3C、3R而不是3C、3L、3R我不知道如何定义这个自定义顺序。有什么想法吗? 最佳答案 尝试这样的事情:(app/models/designator.rb)#determinesthesortvalueforbasedonmy_attribute.#designatorsshoul

ruby-on-rails - rails : to_date with a month/day/year format

我有一个简单的问题。我有一个带有created_at的实例变量。我如何将其转换为Month,day,year~September,13,1987当我尝试=@example.created_at在我看来它给了我1987-09-13奇怪的是,当我在控制台中执行此方法时,我得到了Sun,13Sep1987如何将我的变量转换为月、日、年?为什么它在控制台中返回不同的东西? 最佳答案 您可以通过指定格式来更改日期的显示方式,例如@example.created_at.strftime("%B,%d,%Y")#=>"September,20,2

相当于 python 的 .format() 的 Ruby 字符串插值

在python中我可以做到_str="Mynameis{}"..._str=_str.format("Name")当我尝试在ruby​​中_str="Mynameis#{name}"解释器提示变量name未定义,所以它期待_str="Mynameis#{name}"=>{name=:"Name"}我怎样才能在ruby​​中有一个字符串占位符供以后使用? 最佳答案 您可以使用延迟插值。str="Mynameis%{name}"#=>"Mynameis%{name}"putsstr%{name:"Sam"}#=>"MynameisSam

javascript - rails 3.1 : The new way to use 'respond_to ... format.js' without the 'page' variable

我正在尝试将RubyonRails更新到3.1版本。我关注了UpgradingtoRails3.1截屏视频和所有内容似乎都有效,除了format.js{render(:update){|page|page.redirect_to@article}}在许多Controller中,我有如下代码:defcreate...respond_todo|format|format.js{render(:update){|page|page.redirect_to@article}}endend在上述所有情况下,当我尝试提交执行JS请求的相关表单时,出现以下错误:ActionView::Missing

ruby-on-rails - rails : Using custom classes in Rails

我想将一组自定义对象传递给View层进行渲染。railsexpectstobeabletocall"model_name"以及一系列其他用于在其模型上进行路由的方法。如果我想创建一个可以传递给“render”等方法的自定义类,它需要响应哪些方法?理想情况下,我希望这些对象也可以在rails之外使用。 最佳答案 如果您使用的是Rails3,那么可能值得扩展ActiveModel。查看这些帖子了解更多信息:ActiveModel:MakeAnyRubyObjectFeelLikeActiveRecordRails3.0′sActiveM

javascript - 带 Rails 的 Stripe 4 : This customer has no attached payment source

这个问题在这里已经有了答案:StripetokennotgettingattachedtorequestbodyforRailsApp(1个回答)关闭7年前。在将Stripe(测试模式)与rails4一起使用时,是否有人遇到过此错误:“此客户没有附加的付款来源”?它触发我的user.rb模型中的行(customer=):attr_accessor:stripe_card_tokendefsave_with_paymentifvalid?customer=Stripe::Customer.create(description:email,plan:plan_id,card:stripe_