Rails Tutorialを学習しているプログラミング初心者です。
Rails Tutorial 11章の 11.2.4「ユーザーのcreateアクションの更新」で躓きました。
以下のようにユーザー登録にアカウント有効化を追加したのですが
def create @user = User.new(user_params) if @user.save UserMailer.account_activation(@user).deliver_now flash[:info] = "Please check your email to activate your account." redirect_to root_url else render 'new' end end
以下のそれに対するテストが通らなくて困っています。
test "valid signup information" do get signup_path assert_difference 'User.count', 1 do post users_path, params: { user: { name: "Example User", email: "user@example.com", password: "password", password_confirmation: "password" } } end follow_redirect! #assert_template 'users/show' #assert is_logged_in? end ``` エラーメッセージはこちらです ```ここに言語を入力 ERROR["test_valid_signup_information", UsersSignupTest, 1.0404080669395626] test_valid_signup_information#UsersSignupTest (1.04s) ActionView::Template::Error: ActionView::Template::Error: No route matches {:action=>"edit", :controller=>"account_activations", :email=>"user@example.com", :id=>nil}, possible unmatched constraints: [:id] app/views/user_mailer/account_activation.html.erb:9:in `_app_views_user_mailer_account_activation_html_erb__3563335001904869326_67139240' app/mailers/user_mailer.rb:5:in `account_activation' app/controllers/users_controller.rb:21:in `create' test/integration/users_signup_test.rb:21:in `block (2 levels) in <class:UsersSignupTest>' test/integration/users_signup_test.rb:20:in `block in <class:UsersSignupTest>' ``` ###試したこと 追加した```UserMailer.account_activation(@user).deliver_now``` のコードをコメントアウトしたらテストを通過するのでその辺がおかしいのかと思うのですがどこが違うのかわかりません。 エラーメッセージに書いてあるところを確認したのですが、間違ってるところが見当たりませんでした。 エラーメッセージの意味もよくわかってなくて申し訳ないのですが、ルーティングのどこかのidの値が入ってないってことででしょうか? エラーメッセージに書いてあったファイルはこちらです↓ app/views/user_mailer/account_activation.html.erb:9:in `_app_views_user_mailer_account_activation_html_erb__3563335001904869326_67139240' ```ここに言語を入力 <h1>Sample App</h1> <p>Hi <%= @user.name %>,</p> <p> Welcome to the Sample App! Click on the link below to activate your account: </p> <%= link_to "Activate", edit_account_activation_url(@user.activation_token, email: @user.email) %> ``` app/mailers/user_mailer.rb:5:in `account_activation' ```ここに言語を入力 class UserMailer < ApplicationMailer def account_activation(user) @user = user mail to: user.email, subject: "Account activation" end # Subject can be set in your I18n file at config/locales/en.yml # with the following lookup: # # en.user_mailer.password_reset.subject # def password_reset @greeting = "Hi" mail to: "to@example.org" end end ``` 解決方法がわかる方、お教えいただけませんでしょうか? 宜しくお願いいたします。 ※追記 こちらがconfig/routes.rbです ```ここに言語を入力 Rails.application.routes.draw do root 'static_pages#home' get '/help', to: 'static_pages#help' get '/about', to: 'static_pages#about' get '/contact', to: 'static_pages#contact' get '/signup', to: 'users#new' post '/signup', to: 'users#create' get '/login', to: 'sessions#new' post '/login', to: 'sessions#create' delete '/logout', to: 'sessions#destroy' resources :users resources :account_activations, only: [:edit] end ```
回答3件
あなたの回答
tips
プレビュー