0

特定のコントローラー アクションを使用してユーザーを登録ページにリダイレクトしようとしていますが、機能していません。

私の users_controller.rb には、次のものがあります。

def pre_approved_with_code_action
  @code = params[:code]
  if params[:commit] = 'Cancel'
    redirect_to root_url
    return
  end
  if params[:commit] = 'Create Account'
    flash[:notice] = 'Please register as a new user'
    redirect_to new_user_registration_path(:discount_code => @code)
    return
  end
  if params[:commit] = 'Login And Retry'
    redirect_to new_user_registration_path(:notice => 'Please register as a new user', :discount_code => @code)
    return
  end
end

ログファイルには次のように書かれています:

Started POST "/pre_approved_with_code_action" for 127.0.0.1 at 2013-06-20 10:05:43 -0700

Processing by UsersController#pre_approved_with_code_action as HTML

Parameters: {"utf8"=>"✓", "authenticity_token"=>"sWENK4ZhisSKHQswUZkDcq8ZxsXU+ym9wQqnYwgPIo4=", "code"=>"SPK_2014", "commit"=>"Create Account"}

Redirected to http://localhost:3000/

そのため、new_user_registration_path ではなく root_url にリダイレクトしています。何か案は?

4

2 に答える 2

2

単純な間違いです。等号が 2 つ必要です

代わりif params[:commit] = 'Cancel'if params[:commit] == 'Cancel'

于 2013-06-20T17:20:07.447 に答える
1
def pre_approved_with_code_action
  @code = params[:code]
  if params[:commit] == 'Cancel'
    redirect_to root_url
    return
  end
  if params[:commit] == 'Create Account'
    flash[:notice] = 'Please register as a new user'
    redirect_to new_user_registration_path(:discount_code => @code)
    return
  end
  if params[:commit] == 'Login And Retry'
    redirect_to new_user_registration_path(:notice => 'Please register as a new user', :discount_code => @code)
    return
  end
end

状態は==. =右辺が非 null 値の場合、常に true と評価されます

于 2013-06-20T17:19:36.733 に答える