select_tagの入力をコントローラメソッドに挿入しようとしています。 見たところで問題を解決できないようです。select_tagの入力をレールコントローラに渡すには
これは以下のコードです。ランクの選択のためのものは、まったくパラメータにはありません。
更新コントローラとルート
コントローラと以下
<h1>hello please set <%= @user.username %>'s rank'</h1>
<%= select_tag 'rank', options_for_select(@ranks.collect{ |r| [r.rank_name] }) %>
<%= button_to "Update", :action => "set_user_rank_update", value: "#{@user.id}", method: :post %>
:
class Admin::RankController < ApplicationController
before_action :admin?
def new
@rank = Rank.new
end
def create
@rank = Rank.new(rank_params)
if params["rank"]["admin"].to_i == 1
@rank.toggle! :admin?
end
if @rank.save
flash[:success] = "Rank created"
redirect_to root_path
else
flash[:danger] = "Failed to create rank"
render 'new'
end
end
def set_user_rank_new
@user = User.find_by_id(params["format"])
@ranks = Rank.all
end
def set_user_rank_update
@user = User.find_by_id(params["value"])
@rank = Rank.find_by_id(params["rank"])
@rank_backup = @user.rank.first
debugger
@user.rank - @user.rank.first
@user.rank << @rank
if @user.rank.first == @rank
flash[:success] = "Set user's rank"
redirect_to root_path
else
flash[:danger] = "Failed to set user's rank"
@user.rank - @user.rank.first
@user.rank << @rank_backup
render 'set_user_rank_new'
end
end
private
def rank_params
params.require(:rank).permit(:rank_name, :rank_color)
end
end
ルート
Rails.application.routes.draw do
devise_for :users,
:controllers => { :registrations => "member/registrations" , :sessions => "member/sessions"}
scope module: 'public' do
root 'welcome#index'
end
scope module: 'member' do
get 'members/:id' => 'member#show'
end
scope module: 'admin' do
get 'rank/new' => 'rank#new'
post 'rank/create' => 'rank#create'
get 'rank/set_user_rank/new' => 'rank#set_user_rank_new'
post 'rank/set_user_rank/update' => 'rank#set_user_rank_update'
end
end
コントローラーを追加できますか?私はあなたがどのようにパラメータをチェックしているのか見ることができます – SsouLlesS