vendredi 28 décembre 2018

Rails: How to access session parameter / ActiveRecord::StatementInvalid in Orders#create

I am working on a multistep form for an order placement section which uses a session session[:order_params] to store all form inputs before submit.

I need to be able to access a particular parameter (land) from the session in order to query for another resource (shippingservice) when navigating back in the form.

In my orders_controller.rb I have:

@shippingservices = @cart.available_shipping_services.joins(:lands).where(:lands => {:id => params[:id]})

but would need to specify the land.id from the session[:order_params].

When using session[:order_params] I get ActiveRecord::StatementInvalid in Orders#create:

Mysql::Error: Unknown column 'id.ship_to_last_name' in 'where clause': SELECT `shippingservices`.* FROM `shippingservices` 
INNER JOIN `zones` ON `zones`.`id` = `shippingservices`.`zone_id` 
INNER JOIN `lands_zones` ON `lands_zones`.`zone_id` = `zones`.`id` 
INNER JOIN `lands` ON `lands`.`id` = `lands_zones`.`land_id` 
WHERE `id`.`ship_to_last_name` = 'Smith' 
AND `id`.`ship_to_address` = 'Somewherestreet' 
AND `id`.`ship_to_city` = 'Nowheretown' 
AND `id`.`ship_to_postal_code` = '99999' 
AND `id`.`phone_number` = 'some number' 
AND `id`.`shippingservice_id` = '34' 
AND `id`.`email` = 'someone@example.tld' 
AND `id`.`land_id` = '85' 
AND `id`.`ship_to_first_name` = 'John' 
AND (weightmin <= 200 AND weightmax >= 200 AND heightmin <= 12 AND heightmax >= 12 AND shippingservices.shippingcarrier = '1') AND (lengthmax >= 210 AND widthmax >= 149)

Since the correct land_id is present I am wondering how to provide only that value to the query.

Thank you in advance!

Aucun commentaire:

Enregistrer un commentaire