kali
kali

Reputation: 133

rails parameters not found

I am developing application using stripe for payment. I have Plan and Subscription model in my app. Plan has many subscriptions and subscription belongs t plan. On plans index page i have plans listings and user can click on any of the plans

<td><%=link_to plan.name, new_subscription_path(:plan_id => plan.id) %></td>

and in my subscription controller i have this

def new
 @plan = Plan.find(params[:plan_id])
 @subscription = @plan.subscriptions.new
end

def create
 @plan = Plan.find(params[:plan_id])
 @subscription = @plan.subscriptions.new(subscription_params)

 respond_to do |format|
  if @subscription.save
    format.html { redirect_to @subscription, notice: 'Subscription was successfully created.' }
    format.json { render :show, status: :created, location: @subscription }
  else
    format.html { render :new }
    format.json { render json: @subscription.errors, status: :unprocessable_entity }
  end
 end
end

I am trying to build subscription on particular plan but i am getting this error

Couldn't find Plan with 'id'= 

Upvotes: 0

Views: 28

Answers (1)

Paweł Dawczak
Paweł Dawczak

Reputation: 9639

You should update your config/routes.rb to look like:

resources :plans do
  resources :subscriptions
end

And later in your template, you should use new_plan_subscription_path like:

<td><%=link_to plan.name, new_plan_subscription_path(:plan_id => plan.id) %></td>

This should help!

Good luck!

Upvotes: 1

Related Questions