开发者

Passing parameters in Ruby on Rails (2) Controllers

开发者 https://www.devze.com 2023-02-04 03:19 出处:网络
I\'m having problems passing parameters (in this case, @plan_id) to the next page (new_user_url). class SubscriptionsController < ApplicationController

I'm having problems passing parameters (in this case, @plan_id) to the next page (new_user_url).

class SubscriptionsController < ApplicationController
  #before_filter :require_admin!, :except => [:show]
  skip_before_filter :authenticate_user!, :only => [ :create ]

  def create
    @plan_id = params[:plan]
    if current_user.nil?
      redirect_to new_user_url, :plan_id => @plan_id     
    end
  end
end



class UsersController < ApplicationController
  skip_before_filter :authenticate_user!, :only => [ :new, :create ]
  before_filter :require_admin!, :only => [ :index, :show, :destroy, :signin_as ]

  def new
    logger.debug params
    @user = User.new
    @plan_id = params[:plan_id]
    logger.debug "-------------- plan id: #{@plan_id}"
    @plan = Plan.plan @plan_id
  end

What I see in the debug message is

Processing UsersController#new (for 127.0.0.1 at 2011-01-14 16:07:5开发者_运维百科0) [GET]
  Parameters: {"subdomains"=>["secure"], "controller"=>"users", "action"=>"new"}
{"subdomains"=>["secure"], "controller"=>"users", "action"=>"new"}
-------------- plan id: 

Any pointers to what I'm doing wrong would be much appreciated.

Thanks!


The way you've written your redirect_to call, you're passing the plan_id parameter to the response_status argument. Look at redirect_to documentation:

redirect_to(options = {}, response_status = {}) 

You probably meant to write:

redirect_to new_user_url(:plan_id => @plan_id)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号