<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jason Crockett</title>
    <description>The latest articles on DEV Community by Jason Crockett (@jesusislord3).</description>
    <link>https://dev.to/jesusislord3</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F163447%2F2f9c4297-4645-49e1-bb3f-924cba33d7f0.jpeg</url>
      <title>DEV Community: Jason Crockett</title>
      <link>https://dev.to/jesusislord3</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jesusislord3"/>
    <language>en</language>
    <item>
      <title>Getting arrays in the params hash for sinatra</title>
      <dc:creator>Jason Crockett</dc:creator>
      <pubDate>Thu, 05 Mar 2020 16:14:48 +0000</pubDate>
      <link>https://dev.to/jesusislord3/getting-arrays-in-the-params-hash-for-sinatra-4agh</link>
      <guid>https://dev.to/jesusislord3/getting-arrays-in-the-params-hash-for-sinatra-4agh</guid>
      <description>&lt;p&gt;God or an Angel litterly told me the answer to this one when i was walking out of the bathroom. I am christian coder, and God helps me code.&lt;/p&gt;

&lt;h2&gt;
  
  
  short answer:
&lt;/h2&gt;

&lt;p&gt;do something like this:&lt;br&gt;
&lt;code&gt;&amp;lt;select id="users-select" form="search-form" name="users[]" multiple&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;the key is to have "[]" in the name&lt;/p&gt;

&lt;h2&gt;
  
  
  The story behind it:
&lt;/h2&gt;

&lt;p&gt;so i was writing a search engine for note taking app and i was noticing that in my templates that options that were selected in a multiple choice input only reflected the last option in the url. my url looked like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;http://localhost:4567/reports?clients=5e399c1d181b8942a418c10d&amp;amp;clients=5e52c3f5181b894bcc285cfa&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;so only the option with the value 5e52c3f5181b894bcc285cfa.&lt;/p&gt;

&lt;p&gt;i dispaired slightly having found a (what i thought was a) project crashing bug. Oh no! i thought, im going to have to do double work learning ember or angular or something, specifying the model on front end and the back end stack! and my javascript is a bit lacking! this would push back the completion deadline by months!&lt;/p&gt;

&lt;p&gt;so i decided to try the sinatra param gem which is here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/mattt/sinatra-param"&gt;Sinatra Param Github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;no luck. the types of the param values probably were coerced but params would still only return the last value on the url for that param name.&lt;/p&gt;

&lt;p&gt;so i decided to solve it the only way someone who depends on open source should respond to a problem like this. with prayer and project contribution. so i opened an issue here.. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/sinatra/sinatra/issues/1604"&gt;My Sinatra Repo issue&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and cloned sinatra ready for a pull request after my hack. If God was willing. when im solo, i leave tests until last. but this is a team effort so testing comes first. so i searched in the test folder using rubymines "search in path" command for mentions of params and i came across a behaviour spec at line 575 of this file&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/sinatra/sinatra/blob/master/test/routing_test.rb"&gt;Sinatra/test/routing_test.rb&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;so i noted it in the sinatra issue, shelved it for the night and gamed to 4am because i woke up at 2pm becuase of a persistant migrain and im off sick and working on a project. &lt;/p&gt;

&lt;p&gt;the next day after my post wakeup routine i came out of the bathroom and i heard an angel speak to me.&lt;/p&gt;

&lt;p&gt;he said something like use brackets in the name attributes of my form inputs. Of Coarse! So i went and tried it out to my success and reported it on the sinatra issue and found out that i had a reply. Github user dentarg found a stack exchange question which i hadnt:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/sinatra/sinatra/issues/1604#issuecomment-594817941"&gt;The reply&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/2277185/how-to-get-all-of-the-url-parameters-in-a-sinatra-app"&gt;The Stack Exchange Question&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;They both did not mention how you got the names in the url like that but my angel friend did.&lt;/p&gt;

&lt;p&gt;Thanks God and his messenger!&lt;/p&gt;

</description>
      <category>sinatra</category>
      <category>notes</category>
      <category>jesus</category>
      <category>angel</category>
    </item>
    <item>
      <title>Solve Sinatra helpers not found, one reason</title>
      <dc:creator>Jason Crockett</dc:creator>
      <pubDate>Wed, 19 Feb 2020 20:56:29 +0000</pubDate>
      <link>https://dev.to/jesusislord3/solve-sinatra-helpers-not-found-one-reason-1g14</link>
      <guid>https://dev.to/jesusislord3/solve-sinatra-helpers-not-found-one-reason-1g14</guid>
      <description>&lt;p&gt;This code is wrong because access_db is declared outside of a Sinatra::Base block. app in self.registered is a Sinatra base class with functions. helpers cannot exist outside of those functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; # require_relative '../helpers/models'

        def self.registered(app)
          clients_db = access_db(Archcare::Logbook::Model::Client)
          clients_for_privilege_level = is_admin? ? clients_db.get_all_documents : get_clients_for_user(current_user_id)
          app.get '/client-report' do
            if logged_in?
              erb :creport,locals: {:title =&amp;gt; "New Client Report" ,
                                    :cookie =&amp;gt; has_agreed?,
                                    # get all clients from the database
                                    :clients =&amp;gt; clients_for_privilege_level}
            elsif !logged_in?
              redirect '/login'
            end
            end

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;this code produced this error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Ruby26-x64\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/Users/Jason/source/ArchcareLogbook/app.rb
Models is loaded
C:/Users/Jason/source/ArchcareLogbook/routes/client_report.rb:18:in `registered': undefined method `access_db' for Archcare::Logbook::Routes::ClientReport:Module (NoMethodError)
    from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sinatra-2.0.7/lib/sinatra/base.rb:1415:in `block in register'
    from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sinatra-2.0.7/lib/sinatra/base.rb:1413:in `each'
    from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sinatra-2.0.7/lib/sinatra/base.rb:1413:in `register'
    from C:/Users/Jason/source/ArchcareLogbook/app.rb:50:in `&amp;lt;class:Logbook&amp;gt;'
    from C:/Users/Jason/source/ArchcareLogbook/app.rb:30:in `&amp;lt;module:Logbook&amp;gt;'
    from C:/Users/Jason/source/ArchcareLogbook/app.rb:4:in `&amp;lt;module:Archcare&amp;gt;'
    from C:/Users/Jason/source/ArchcareLogbook/app.rb:3:in `&amp;lt;top (required)&amp;gt;'
    from -e:1:in `load'
    from -e:1:in `&amp;lt;main&amp;gt;'

Process finished with exit code 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;hope this helps!&lt;/p&gt;

</description>
      <category>sinatra</category>
      <category>ruby</category>
    </item>
  </channel>
</rss>
