前提・実現したいこと
Railsでcurrent_userのマイページで登録情報を変更する際に管理者に一旦変更依頼を送信して変更依頼を元に管理画面で管理者が該当ユーザーの登録情報を変更するシステムを作成したい。
Userテーブルに定義された(ex. :country, :city, :number..etc)を入力するが、別テーブル(Askテーブル)に定義した(ex. :contents)にまとめて登録したい。
該当のソースコード
asks_controller.rb
def new @ask = Ask.new end def confirm @ask = Ask.new(ask_params) end def create @ask = Ask.new(ask_params) return render :new if params[:back] return render :new unless @ask.save redirect_to action: 'finish' end def finish end private def ask_params params.require(:ask).permit( :country, :city, :number, :contents ) end
models/ask.rb
belongs_to :user attr_accessor :country, :city, :number
new.slim
= form_for @ask, url: hoge_path do |f| = f.label :country = f.text_field :description = f.label :city = f.text_field :description = f.label :number = f.text_field :description = f.submit '確認画面へ'
confirm.slim
= form_for @ask, url: hoge_path do |f| - if @ask.country.present? = f.label :country = f.hidden_field :description - if @ask.country.present? = f.label :city = f.hidden_field :description - if @ask.country.present? = f.label :number = f.hidden_field :description = f.submit '変更依頼する'
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。