yatmsu
2/12/2015 - 2:00 AM

app/controllers/application_controller.rb

app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
  private
    # ActionMailerのdefault_url_optionsを変更する
    def set_default_url_options; ActionMailer::Base.default_url_options[:host] = request.host_with_port end 
end

class UsersController < ApplicationController                                                                                                                                       
  before_action :set_user, only: [:show, :edit, :update, :destroy]
  before_action :set_default_url_options, only: [:create, :update]
 
  # POST /users                                                                                                                                                                     
  # POST /users.json                                                                                                                                                                
  def create                                                                                                                                                                        
    @user = User.new(user_params)

    respond_to do |format|                                                                                                                                                          
      if @user.register                                                                                                                                                             
        format.html { redirect_to @user, notice: t('users.notices.create') }                                                                                                        
        format.json { render :show, status: :created, location: @user }                                                                                                             
      else                                                                                                                                                                          
        format.html { render :new }                                                                                                                                                 
        format.json { render json: @user.errors, status: :unprocessable_entity }                                                                                                    
      end                                                                                                                                                                           
    end                                                                                                                                                                             
  end

  private
    def set_user; @user = User.find params[:id] end
end