質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

1059閲覧

railsチュートリアル第11章の途中でsign upをしたらArgumentError in Users#createとエラーが出てしまい解決できずに困っています。

kazuki_0311

総合スコア7

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2019/09/09 14:17

編集2019/09/10 05:32

前提・実現したいこと

railsチュートリアルの第11章の途中でsign upをしたら
ArgumentError in Users#createというエラーが出てしまい、
色々試したのですがどうしても解決できず困っています。

メールのアカウント有効化系の実装をしていてエラーが出たと思われます。
(曖昧ですみません。)

発生している問題・エラーメッセージ

エラー名→「ArgumentError in Users#create

Showing /home/ec2-user/environment/sample_app/app/views/user_mailer/account_activation.html.erb where line #9 raised: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

該当のソースコード

・ファイル名→「account_activation.html.erb」 ・以下コード↓ <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) %>
・ファイル名→「user_mailer.rb」 ・以下コード↓ class UserMailer < ApplicationMailer def account_activation(user) @user = user mail to: user.email, subject:"Account activation" end def password_reset @greeting = "Hi" mail to: "to@example.org" end end
・ファイル名→「users_controller.rb」 ・以下コード↓ class UsersController < ApplicationController before_action :logged_in_user,only:[:index,:edit,:update,:destroy] before_action :correct_user,only:[:edit,:update] before_action :admin_user,only: :destroy def index @users = User.paginate(page:params[:page]) end def show @user = User.find(params[:id]) end def new @user = User.new end 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 def edit end def update if @user.update_attributes(user_params) flash[:success] = "Profile updated" redirect_to @user else render'edit' end end def destroy User.find(params[:id]).destroy flash[:success]="User deleted" redirect_to users_url end private def user_params params.require(:user).permit(:name, :email, :password, :password_confirmation) end def logged_in_user unless logged_in? store_location flash[:danger] ="Please log in." redirect_to login_url end end def correct_user @user=User.find(params[:id]) redirect_to(root_url)unless current_user?(@user) end def admin_user redirect_to(root_url) unless current_user.admin? end end
・ファイル名→「development.rb」 ・以下コード↓ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false # Do not eager load code on boot. config.eager_load = false # Show full error reports. config.consider_all_requests_local = true # Enable/disable caching. By default caching is disabled. if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true config.cache_store = :memory_store config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}" } else config.action_controller.perform_caching = false config.cache_store = :null_store end # Don't care if the mailer can't send. config.action_mailer.rails_delivery_errors = true config.action_mailer.delivery_method =:test host ='a74a1e0d17164030933c4775e8454142.vfs.cloud9.ap-southeast-1.amazonaws.com' config.action_mailer.default_url options = {host:host,protocol:'https'} config.action_mailer.perform_caching = false # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. config.assets.debug = true # Suppress logger output for asset requests. config.assets.quiet = true # Raises error for missing translations # config.action_view.raise_on_missing_translations = true # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker end

試したこと

エラーに該当しているファイルにコードの書き間違いがないかを
railsチュートリアルにある見本コードと見比べたのですがどこも間違っておらず。

関係ありそうな、
メールでのアカウント有効化のメールが遅れているのかどうかも
一応確認しようと試みたのですが、
ググってもどこを確認すれば良いのかわからず断念。

恐れ入りますがこのエラーの解決方法を
ご存知の方がいらしたら教えていただけると非常に助かります。
どうかよろしくお願いします。

補足情報(FW/ツールのバージョンなど)

railsチュートリアル
rails 5.1.6
AWS Cloud9を使用

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

解決しました。
ありがとうございました!

投稿2019/09/10 09:45

kazuki_0311

総合スコア7

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問