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












0














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!










share|improve this question



























    0














    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!










    share|improve this question

























      0












      0








      0







      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!










      share|improve this question













      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!







      ruby-on-rails ruby-on-rails-3 session activerecord session-variables






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 28 '18 at 11:10









      SEJUSEJU

      226211




      226211
























          2 Answers
          2






          active

          oldest

          votes


















          1














          As per the description mentioned in the post, you want to access a particular key stored in session at a particular key.



          Assuming order_params is a hash, you can get land_id using the below mentioned code:



          session[:order_params][:land_id]


          This will return the value of land_id and thus you can use it in the query.






          share|improve this answer





















          • Thank you for your reply. Unfortunately it does not work. I have more details here: stackoverflow.com/questions/53953658/…
            – SEJU
            Dec 28 '18 at 13:41



















          1














          To set session variable, you can set some data in a controller action
          For eg:
          app/controllers/sessions_controller.rb



          def create
          # ...
          session[:current_user_id] = @user.id
          # ...
          end


          And read it in another: app/controllers/users_controller.rb



          def index
          current_user = User.find_by_id(session[:current_user_id])
          # ...
          end





          share|improve this answer





















          • Thanks for your reply. I know, but in this case I need to access a value saved inside the order_params or do you mean I have to create another session or specify another session?
            – SEJU
            Dec 28 '18 at 11:28











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53957592%2frails-how-to-access-session-parameter-activerecordstatementinvalid-in-order%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          As per the description mentioned in the post, you want to access a particular key stored in session at a particular key.



          Assuming order_params is a hash, you can get land_id using the below mentioned code:



          session[:order_params][:land_id]


          This will return the value of land_id and thus you can use it in the query.






          share|improve this answer





















          • Thank you for your reply. Unfortunately it does not work. I have more details here: stackoverflow.com/questions/53953658/…
            – SEJU
            Dec 28 '18 at 13:41
















          1














          As per the description mentioned in the post, you want to access a particular key stored in session at a particular key.



          Assuming order_params is a hash, you can get land_id using the below mentioned code:



          session[:order_params][:land_id]


          This will return the value of land_id and thus you can use it in the query.






          share|improve this answer





















          • Thank you for your reply. Unfortunately it does not work. I have more details here: stackoverflow.com/questions/53953658/…
            – SEJU
            Dec 28 '18 at 13:41














          1












          1








          1






          As per the description mentioned in the post, you want to access a particular key stored in session at a particular key.



          Assuming order_params is a hash, you can get land_id using the below mentioned code:



          session[:order_params][:land_id]


          This will return the value of land_id and thus you can use it in the query.






          share|improve this answer












          As per the description mentioned in the post, you want to access a particular key stored in session at a particular key.



          Assuming order_params is a hash, you can get land_id using the below mentioned code:



          session[:order_params][:land_id]


          This will return the value of land_id and thus you can use it in the query.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 28 '18 at 13:31









          RohanRohan

          1,1821311




          1,1821311












          • Thank you for your reply. Unfortunately it does not work. I have more details here: stackoverflow.com/questions/53953658/…
            – SEJU
            Dec 28 '18 at 13:41


















          • Thank you for your reply. Unfortunately it does not work. I have more details here: stackoverflow.com/questions/53953658/…
            – SEJU
            Dec 28 '18 at 13:41
















          Thank you for your reply. Unfortunately it does not work. I have more details here: stackoverflow.com/questions/53953658/…
          – SEJU
          Dec 28 '18 at 13:41




          Thank you for your reply. Unfortunately it does not work. I have more details here: stackoverflow.com/questions/53953658/…
          – SEJU
          Dec 28 '18 at 13:41













          1














          To set session variable, you can set some data in a controller action
          For eg:
          app/controllers/sessions_controller.rb



          def create
          # ...
          session[:current_user_id] = @user.id
          # ...
          end


          And read it in another: app/controllers/users_controller.rb



          def index
          current_user = User.find_by_id(session[:current_user_id])
          # ...
          end





          share|improve this answer





















          • Thanks for your reply. I know, but in this case I need to access a value saved inside the order_params or do you mean I have to create another session or specify another session?
            – SEJU
            Dec 28 '18 at 11:28
















          1














          To set session variable, you can set some data in a controller action
          For eg:
          app/controllers/sessions_controller.rb



          def create
          # ...
          session[:current_user_id] = @user.id
          # ...
          end


          And read it in another: app/controllers/users_controller.rb



          def index
          current_user = User.find_by_id(session[:current_user_id])
          # ...
          end





          share|improve this answer





















          • Thanks for your reply. I know, but in this case I need to access a value saved inside the order_params or do you mean I have to create another session or specify another session?
            – SEJU
            Dec 28 '18 at 11:28














          1












          1








          1






          To set session variable, you can set some data in a controller action
          For eg:
          app/controllers/sessions_controller.rb



          def create
          # ...
          session[:current_user_id] = @user.id
          # ...
          end


          And read it in another: app/controllers/users_controller.rb



          def index
          current_user = User.find_by_id(session[:current_user_id])
          # ...
          end





          share|improve this answer












          To set session variable, you can set some data in a controller action
          For eg:
          app/controllers/sessions_controller.rb



          def create
          # ...
          session[:current_user_id] = @user.id
          # ...
          end


          And read it in another: app/controllers/users_controller.rb



          def index
          current_user = User.find_by_id(session[:current_user_id])
          # ...
          end






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 28 '18 at 11:19









          Sss SharmaSss Sharma

          1013




          1013












          • Thanks for your reply. I know, but in this case I need to access a value saved inside the order_params or do you mean I have to create another session or specify another session?
            – SEJU
            Dec 28 '18 at 11:28


















          • Thanks for your reply. I know, but in this case I need to access a value saved inside the order_params or do you mean I have to create another session or specify another session?
            – SEJU
            Dec 28 '18 at 11:28
















          Thanks for your reply. I know, but in this case I need to access a value saved inside the order_params or do you mean I have to create another session or specify another session?
          – SEJU
          Dec 28 '18 at 11:28




          Thanks for your reply. I know, but in this case I need to access a value saved inside the order_params or do you mean I have to create another session or specify another session?
          – SEJU
          Dec 28 '18 at 11:28


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53957592%2frails-how-to-access-session-parameter-activerecordstatementinvalid-in-order%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas