我正在使用设计宝石处理所有注册和登录的东西.但我还想将用户配置文件添加到我的应用程序中,因此我生成了一个只有show动作的用户控制器.然后我添加get 'users/:id' => 'users#show'到routes.rb.事实上,输入/ users/1有效,但我找不到一种方法来命名路线.我想要的是获得像show_user_path或user_path这样的东西,这样我就可以链接到给定用户的内容并显示该用户的个人资料.
这是我的routes.rb
Pinteresting::Application.routes.draw do
resources :pins
get 'users/:id' => 'users#show'
devise_for :users
root "pins#index"
get "about" => "pages#about"
Run Code Online (Sandbox Code Playgroud)
这是我得到的路线(我突出了我期望的那样像show_user_path):
pins_path GET /pins(.:format) pins#index
POST /pins(.:format) pins#create
new_pin_path GET /pins/new(.:format) pins#new
edit_pin_path GET /pins/:id/edit(.:format) pins#edit
pin_path GET /pins/:id(.:format) pins#show
PATCH /pins/:id(.:format) pins#update
PUT /pins/:id(.:format) pins#update
DELETE /pins/:id(.:format) pins#destroy
#this is the one I want a path! GET /users/:id(.:format) users#show
new_user_session_path GET /users/sign_in(.:format) devise/sessions#new
user_session_path POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session_path DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password_path POST …Run Code Online (Sandbox Code Playgroud) 我是一个全新的人,我正在学习Ruby on Rails和Michael Hartl的教程.我在第3章,关于页面的Rspec测试失败(而完全相同的测试并没有失败的主页和帮助页面).
我在运行时遇到的错误$ bundle exec rspec spec/requests/static_pages_spec.rb是:
Failures:
1) Static pages About page should have the content 'About Us'?[31mFailure/Error:?[0m ?[31mvisit 'static_pages/about'?[0m?[31mURI::InvalidURIError?[0m:?[31mthe scheme http does not accept registry part: www.example.com:80static_pages (or bad hostname?)?[0m?[36m # ./spec/requests/static_pages_spec.rb:24:in `block (3 levels) in <top (required)>'?[0m Finished in 0.0776 seconds?[31m3 examples, 1 failure?[0m
Failed examples:
?[31mrspec ./spec/requests/static_pages_spec.rb:23?[0m ?[36m# Static pages About page should have the content 'About Us'?[0m
Run Code Online (Sandbox Code Playgroud)
当访问http://localhost:3000/static_pages/about页面加载时,我可以在大H1字母中看到"关于我们".
规格/请求/ static_pages_spec.rb:
require 'spec_helper'
describe "Static pages" do
describe "Home page" …Run Code Online (Sandbox Code Playgroud)