Mei
Mei

Reputation: 243

Passing parameters in Ruby on Rails (2) Controllers

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:50) [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!

Upvotes: 1

Views: 1048

Answers (1)

Nicolas Buduroi
Nicolas Buduroi

Reputation: 3584

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)

Upvotes: 2

Related Questions