Slide 12
Slide 12 text
class UsersController < ApplicationController
before_action :new_one, only: [:new, :create]
def new; end
def create
if @user.save
create_success_response_to
else
create_error_response_to
end
end
def new_one
@user = scope.new(one_params)
end
def create_success_response_to
respond_to do |format|
format.html {
flash[:notify_success] = "࡞͠·ͨ͠"
redirect_to { action: :index }
}
format.json {
render json: @user.to_json
}
end
end
def create_error_response_to
respond_to do |format|
format.html {
flash[:notify_error] = "࡞Ͱ͖·ͤΜͰͨ͠"
# …
͜͏ৼΔ͏
2 ߦॻ͚ͩ͘Ͱ
class UsersController < ApplicationController
include CrudController
crud_controller User, [:new, :create]
end