Tag: rails routing

在Rails路由中测试什么?

我很好奇人们认为对路线进行充分/彻底的测试。 我工作的人似乎想要在我们的路线文件中断言每条路线,无论标准如何。 我觉得这是浪费时间,但也许我错了,我不知道这有什么价值。 在某些情况下,我可以在路由中看到一些价值。 我们仍然有一些响应GET和POST请求的动作,尽管我一直想要摆脱它们。 我们没有任何关于lambdas或任何东西的疯狂约束,但是如果我们这样做,那似乎值得测试。 但是对于正常的资源定义? resources :foo, only: [:index, :show] 我们断言这两条路线都存在,我们声称它们是GET并且它们会转到正确的控制器/动作。 这有什么意义吗? 感觉就像我们刚刚测试Rails一样。 在一个稍微相关的问题上,我更喜欢定义像上面那样的资源路径( only: [:index, :show]部分)。 仅定义resources :foo是否有任何后果resources :foo如果该控制器上只有索引/显示操作,则路径文件中为resources :foo ? 在我看来,它可能只是使用更多的时间和/或内存,但它是否也是一个安全问题,或者是我不知道的非常糟糕的东西?

如何获取与我的url的最终参数匹配*的铁路路线?

我想允许用户在url中使用加密密码时自动登录。 我有以下url,我想与rails路由匹配: /attendants/update_player_status/game/1/maybe/user_hash/$2a$10$1kY8xvOjkqZJJJGWDd0q2Oeyl7kICSBDPTYzGhkJ6pZnE6YA/nJie url的后半部分可以有任何字符,比如*(即它可以有’/”$”*’等) 我的路线有效,但随后它会在参数中弹出“/”(如上所示): match ‘/attendants/update_player_status/game/:game_id/:status/user_hash/:user_hash’ => ‘attendants#update_player_status_using_hash’, :as => ‘update_player_status_using_hash’ 关于我应该做什么的任何建议? 一旦我正确地拉出参数,我将使用它来登录用户进入网站,并允许非常有限的访问。

使用Authlogic和Rails 3.2.9时的路由错误

我已经通过引用https://github.com/jonathandean/authlogic_example为用户管理需求配置了authlogic gem。 我已经正确配置了一切。 我使用的是Rails 3.2.9和ruby 1.8.7。 当我使用localhost:3000时,我收到以下错误 Routing Error undefined method `filter_parameter_logging’ for ApplicationController:Class Try running rake routes for more information on available routes. 请帮忙解决这个问题。 谢谢你的帮助 :)-

Rails设计不适用于localhost上的rails 3.2.1

我按照本教程中讨论的每个步骤设计我的本地主机 – http://www.slideshare.net/wleeper/devise-and-rails upto page 8 of 22我希望同一个用户登录forms如第8页所述,但除此之外,我收到此错误 – 如果我保留在routes.rb文件中的注释, #matate’:controller(/:action(/:id))(:format)’ 然后这个消息标志 – 当我取消注释这一行时,它会显示此错误 – 关于rails的想法非常少,因为我来自PHP背景,但仍然在理论之前尝试一些实际测试,所以让我知道我究竟做错了什么。 我的routes.rb文件 – Prjmgt::Application.routes.draw do devise_for :users # The priority is based upon order of creation: # first created -> highest priority. # Sample of regular route: # match ‘products/:id’ => ‘catalog#view’ # Keep in mind you can assign values […]

Ruby on Rails 3.2.13 – 使用I18n获取自定义错误页面的错误

我有一个Rails 3.2.13应用程序,我最初使用路由filtergem为I18n。 我计划在Rails 4中重写它。我删除了gem,因为没有可用的Rails 4生产版本​​,我无法让beta版本工作。 我成功地为大多数应用程序设置了路由。 我唯一的问题是我的自定义错误页面。 我在使用routing-filter gem时创建了自定义错误页面。 我需要有关如何为自定义错误页面设置路由的帮助。 以下是我在config / application.rb中进行配置的方法 config.exceptions_app = self.routes 这是我在application_controller.rb中的内容 before_filter :set_locale def default_url_options(options={}) { :locale => I18n.locale } end private def set_locale I18n.locale = (params[:locale] if params[:locale].present?) || cookies[:locale] || ‘en’ cookies[:locale] = I18n.locale if cookies[:locale] != I18n.locale.to_s end 这是我在使用路由filtergem时在路由文件中的内容。 match “/404”, to: ‘errors#error_404’ match “/500”, to: […]

如果从特定路由调用创建方法,如何检查validation?

如果从其他路径调用创建方法,我想在创建方法上validation列存在。 例如,如果我有以下两条路线: post ‘create_item’, to: ‘item#create’ post ‘create_verified_item’, to: ‘item#create_verified’ 我需要在Item模型中定义这样的东西: validates :verified_number, presence: true, if: Item.action_name == “create_verified” 有人可以帮忙吗?

Rails – 基于主机和ID的动态路由

我有一个包含许多用户页面的rails应用程序。 当用户想要在此页面指向域名时,我该怎么做? 现在我已经测试了这个,它的工作原理 – root :to => “controller#show”, :id => 4, :constraints => {:host => “www.exampleurl.com”} 但需要将其转换为动态,以便在将列迁移到名为domain的模型后,它会检查domain并为其提供正确的ID。 就像是 – root :to => ‘controller#show’, :id => ‘:id’, :constraints => {:host => ‘:domain’} 这会是什么样的?

非资源嵌套的命名路由

我正在尝试生成一个用户点击确认其帐户的链接。 我想要这个: /users/:id/confirm/:code 我在我的路线文件中有这个: resources :users do member do get ‘confirm/:confirmation_code’, :action => ‘confirm’ end end 我试过了: user_confirm_path(@user, @confirmation_code) confirm_user_path(@confirmation_code, @user) 和其他许多人一样,但似乎无法找到正确的人。 我想我总是可以自己生成链接url,但这似乎不是轨道方式。 这是我的rake路线输出: rake routes Prefix Verb URI Pattern Controller#Action GET /users/:id/confirm/:confirmation_code(.:format) users#confirm 但是省略了我正在寻找的东西

Rails RSpec请求规范失败,因为意外的%2F添加到重定向响应

在config / routes.rb中: get ‘books(/*anything)’ => redirect( “/public/%{anything}” ), :format => false 在spec / requests / store_request_spec.rb中: get ‘/books/aoeu/snth’ expect(response).to redirect_to( ‘/public/aoeu/snth’ ) 这失败了: Failure/Error: expect(response).to redirect_to( ‘/public/aoeu/snth’ ) Expected response to be a redirect to but was a redirect to . Expected “http://www.example.com/public/aoeu/snth” to be === “http://www.example.com/public/aoeu%2Fsnth”. # ./spec/requests/store_request_spec.rb:14:in `block (3 levels) in ‘ […]

插入的命名路由。 代替 /

我在rails 4中的命名路由遇到了问题( 非资源嵌套的命名路由 )。 我已经转移到其他东西,但仍然在努力解决非资源url的命名路由问题。 这是我从rake routes : GET /messages/:id/report/:reply_token(.:format) messages#report messages POST /messages(.:format) messages#create 和我的routes.rb resources :messages, only: [:create] do member do get ‘report/:reply_token’, :action => ‘report’#, :as => :message end end 由于我在顶部链接的post中遇到的问题,我正在尝试通过执行以下操作获取/ messages /:id / report /:reply_token路由的URL: “#{messages_url(@message, :host => “localhost:3000″)}/report/#{@message.reply_token}” 但它给了我这个: http://localhost:3000/messages.110/report/6bBw22TdaRYcQ3iVzW1ZwA 为什么会有。 在’messages’和’110’(message_id)之间? 我还在messages_url()尝试了@ message.id,而不是@message。 我也尝试了这个: report_message_path(message_id: @message.id, reply_token: @message.reply_token)但是得到了与上面链接的问题相同的错误。 我也尝试过message_url()但它给出了undefined […]