Tag: actionpack

Rails 4.1.2 – to_param转义斜杠(并打破app)

我在我的应用程序to_param使用创建自定义URL(此自定义路径包含斜杠): class Machine < ActiveRecord::Base def to_param MachinePrettyPath.show_path(self, cut_model_text: true) end end 问题是,由于Rails 4.1.2行为已更改且Rails不允许在URL中使用斜杠(使用自定义URL时),因此它会转义斜杠。 我有这样的路线: Rails.application.routes.draw do scope “(:locale)”, locale: /#{I18n.available_locales.join(“|”)}/ do resources :machines, except: :destroy do collection do get :search get ‘search/:ad_type(/:machine_type(/:machine_subtype(/:brand)))’, action: ‘search’, as: :pretty_search get ‘:subcategory/:brand(/:model)/:id’, action: ‘show’, as: :pretty patch ‘:subcategory/:brand(/:model)/:id’, action: ‘update’ # To be able to update machines with […]

我如何要求NumberHelper并使其工作?

我正在尝试编写一个简单的Sinatra,但我需要ActionBox中的ActionView :: Helpers :: NumberHelper。 http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html 问题是,我该如何安装和使用它? irb(main):001:0> require ‘action_view/helpers/number_helper’ irb(main):002:0> number_with_precision(1) NoMethodError: undefined method `number_with_precision’ for main:Object irb(main):004:0> ActionView::Helpers::NumberHelper.number_with_precision(1) NoMethodError: undefined method `number_with_precision’ for ActionView::Helpers::NumberHelper:Module 为什么这个简单的步骤不起作用? 而且,如果我需要所有废话: irb(main):001:0> require ‘action_pack’ irb(main):004:0> require ‘action_view’ irb(main):005:0> include ActionView::Helpers::NumberHelper irb(main):006:0> number_to_phone(12345) NoMethodError: undefined method `starts_with?’ for “12345”:String 如何理解这一切? 为什么这个模块不起作用? 为什么它不需要它需要什么? 它需要什么? starts_with在哪里? 谷歌对这些问题完全保持沉默。 UPD:现在我得到以下内容 number_with_precision(1, :locale => […]

与Rails中的url_for相反的是什么? 获取路径并生成解释路线的函数?

大脑有点油炸….我如何得到:控制器的哈希和来自relative_path的动作? 这基本上与url_for相反。 在下面的例子中,“some_function”是我正在寻找的神秘函数名称……我知道它很简单,只是记不住或者似乎无法在文档中找到它。 像这样: some_function(‘/posts/1/edit’) => {:controller => ‘posts’, :action => ‘edit’, :id => ‘1’}