Ruby初心者です。
過去の記事を色々、調べたのですが中々エラーを解決することが出来ず、困っています。
内容としましては、
Error:
1UsersControllerTest#test_should_get_show: 2ActionController::UrlGenerationError: No route matches {:action=>"show", :controller=>"users"}, missing required keys: [:id] 3 test/controllers/users_controller_test.rb:5:in `block
というエラーが表示され、テストが通りません。
rails routesでルーティングを調べましたところ、
user GET /users/:id(.:format) users#show
と表示されたので、ルーティングは間違っていないと思っています。
以下に、users_controller.rbとusers_controller.test.rbのコードを載せさせて頂きます。
初学者につき、質問の仕方にも至らない点もあるとは思いますが、
ご回答して頂けたら幸いです。
users_controller.rb
class UsersController < ApplicationController def show @user = User.find(params[:id]) end def index @users = User.all end end
users_controller.test.rb
test "should get show" do get user_path assert_response :success end
show.html.erb
<div class="row"> <aside class="col-md-4"> <section class="user_info"> <h1> <%= gravatar_for @user %> <%= @user.name %> </h1> </section> <li><%= link_to 'プロフィール変更', edit_user_registration_path %></li> </aside> </div>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/15 08:33