inside supplied block; # resets Time.zone to existing value when done. class ApplicationController < ActionController::Base around_action :set_time_zone private def set_time_zone Time.use_zone(current_user.timezone) { yield } end end # app/models/user.rb class User < ApplicationRecord has_many :branch_users, dependent: :destroy has_many :branches, through: :branch_users end • ίϯτϩʔϥʔͷ around_actionͰׅΔํ🙆
inside supplied block; # resets Time.zone to existing value when done. class ApplicationController < ActionController::Base around_action :set_time_zone private def set_time_zone Time.use_zone(current_user.timezone) { yield } end end # app/models/user.rb class User < ApplicationRecord has_many :branch_users, dependent: :destroy has_many :branches, through: :branch_users end # app/models/branch.rb class Branch < ApplicationRecord def time_zone # 'Asia/Tokyo'͔'Asia/Bangkok'Λฦ͢ end end • ίϯτϩʔϥʔͷ around_actionͰׅΔํ🙆 • ͨͩ͠λΠϜκʔϯΛ࣋ͭͷ UserͰͳ͘Branch
end private def set_time_zone(&block) if branch_id Time.use_zone(Branch.find_by(id: branch_id).time_zone, &block) else yield end end # Override this method in the including controller if necessary def branch_id @branch&.id end end
end private def set_time_zone(&block) if branch_id Time.use_zone(Branch.find_by(id: branch_id).time_zone, &block) else yield end end # Override this method in the including controller if necessary def branch_id @branch&.id end end
@appointment = Appointment.new end def create @appointment = Appointment.new(appointment_params) if @appointment.save redirect_to staff_appointments_path end end private def appointment_params permitted_params = %i[title starts_at ends_at branch_id memo] params.fetch(:appointment, {}).permit(permitted_params) end end end
@appointment = Appointment.new end def create @appointment = Appointment.new(appointment_params) if @appointment.save redirect_to staff_appointments_path end end private def appointment_params permitted_params = %i[title starts_at ends_at branch_id memo] params.fetch(:appointment, {}).permit(permitted_params) end end end
@appointment = Appointment.new end def create @appointment = Appointment.new(appointment_params) if @appointment.save redirect_to staff_appointments_path end end private def appointment_params permitted_params = %i[title starts_at ends_at branch_id memo] params.fetch(:appointment, {}).permit(permitted_params) end end end λΠߍࣷͳͷʹ ຊ࣌ؒͷ12࣌Ͱ อଘ͞ΕΔ😥
def new @appointment = Appointment.new end def create @appointment = Appointment.new(appointment_params) if @appointment.save redirect_to staff_appointments_path end end private def branch_id appointment_params[:branch_id] end def appointment_params permitted_params = %i[title starts_at ends_at branch_id memo] params.fetch(:appointment, {}).permit(permitted_params) end end end
def new @appointment = Appointment.new end def create @appointment = Appointment.new(appointment_params) if @appointment.save redirect_to staff_appointments_path end end private def branch_id appointment_params[:branch_id] end def appointment_params permitted_params = %i[title starts_at ends_at branch_id memo] params.fetch(:appointment, {}).permit(permitted_params) end end end ຊ࣌ؒͷ14࣌ (λΠ࣌ؒͷ12࣌👍)
before_action :set_appointment, only: %i[edit] > def new; end > def create; end > def edit; end private def branch_id appointment_params[:branch_id] end def set_appointment @appointment ||= Appointment.find(params[:id]) end > def appointment_params; end end end
before_action :set_appointment, only: %i[edit] > def new; end > def create; end > def edit; end private def branch_id appointment_params[:branch_id] end def set_appointment @appointment ||= Appointment.find(params[:id]) end > def appointment_params; end end end
before_action :set_appointment, only: %i[edit] > def new; end > def create; end > def edit; end private def branch_id appointment_params[:branch_id] end def set_appointment @appointment ||= Appointment.find(params[:id]) end > def appointment_params; end end end editΞΫγϣϯͰnil😢
before_action :set_appointment, only: %i[edit] > def new; end > def create; end > def edit; end private def branch_id case action_name when ‘edit' set_appointment @appointment.branch_id when 'create' appointment_params[:branch_id] end end def set_appointment @appointment ||= Appointment.find(params[:id]) end > def appointment_params; end end end
before_action :set_appointment, only: %i[edit] > def new; end > def create; end > def edit; end private def branch_id case action_name when ‘edit' set_appointment @appointment.branch_id when 'create' appointment_params[:branch_id] end end def set_appointment @appointment ||= Appointment.find(params[:id]) end > def appointment_params; end end end 🎉
before_action :set_appointment, only: %I[edit update] > def new; end > def create; end > def edit; end > def update; end private def branch_id case action_name when ‘edit' set_appointment @appointment.branch_id when 'create', 'update' appointment_params[:branch_id] end end def set_appointment @appointment ||= Appointment.find(params[:id]) end > def appointment_params; end end end ΞΫγϣϯ͝ͱʹ ಓʹbranch_idΛ ઃఆ͍ͯ͘͠