mardi 27 décembre 2016

Why is my rails 4.2 controller's if statement not working with a url parameter?

I have a standard pricing plan table on my website. When a visitor picks a plan they get a url with a plan id in it. I'm offering two types of services, blog maintenance and online store maintenance. I have the following if statement in my controller and it works if someone picks a blog plan but doesn't work for a store plan. It always wants to run the functions for the blog even if there is no blog plan parameter in the url.

if params[:user][:blogs][:bplan_id].present?
create_new_blog_customer
create_blog
elsif params[:user][:stores][:splan_id].present?
create_new_store_customer
create_store
end

I have also tried the following which works the same way (blog works but store doesn't).

if @selected_bplan_id.present?
create_new_blog_customer
create_blog
else
create_new_store_customer
create_store
end

The selected plan variable is setup like so:

def new
prepare_meta_tags title: "Create Your Account"
set_meta_tags noindex: true
@account = Account.new
@user = User.new
@blog = Blog.new
@store = Store.new
@selected_bplan_id = params[:bplan_id]
@selected_splan_id = params[:splan_id]
end

Aucun commentaire:

Enregistrer un commentaire