title: running curl on ruby on rails
body: <p>I have a rails application where a user can create the tickets. </p>
  
  <p>Name of My application: tickets
   a user has to submit some information to create the ticket (name, seat_id, address, price, email).</p>
  
  <p>when the user click on the Create button. It creates the ticket and submits the data into the mysql DB. which is working fine.</p>
  
  <p>I actually want to run a curl script whenever a person clicks on the Create button. So that I can take the data (name, seat_id, address, price, email) and import it into redcap DB (another project).</p>
  
  <p>this is the curl command:</p>
  
  <pre><code># Set secret token specific to your REDCap project
  TOKEN="YOUR_TOKEN"
  
  # Set the url to the api (ex. https://YOUR_REDCAP_INSTALLATION/api/)
  SERVICE="YOUR_API_URL"
  
  # UPLOAD a flat csv record contain in file file (/path/to/my.csv) 
  # Note the use of '&lt;' to get curl to read in data from external file
  curl    --form token=${TOKEN} \
          --form overwriteBehavior=normal \
          --form content=record  
          --form format=csv 
          --form type=flat \
          --form data="&lt;/path/to/my.csv" \
          ${SERVICE}
  </code></pre>
  
  <p>Here at the place of .csv file, I have to pass the variables value (name, seat_id, address, price, email)</p>
  
  <p>tickets_controller.rb</p>
  
  <pre><code>  # POST /tickets
    # POST /tickets.json
  def create
  
  respond_to do |format|  
    @ticket = Ticket.new(ticket_params)
  
    if @ticket.save
      format.html { redirect_to @ticket, notice: 'Ticket was successfully created.' }
      format.json { render :show, status: :created, location: @ticket }
  
      # Set secret token specific to your REDCap project
      @TOKEN="YOUR_TOKEN"
  
      # Set the url to the api (ex. https://YOUR_REDCAP_INSTALLATION/api/)
      @SERVICE="YOUR_API_URL"
  
      # UPLOAD a flat csv record contain in file file (/path/to/my.csv) 
      # Note the use of '&lt;' to get curl to read in data from external file
      system(curl    --form token=${@TOKEN} \
                      --form overwriteBehavior=normal \
                      --form content=record  
                      --form format=csv 
                      --form type=flat \
                      --form data="&lt;/path/to/my.csv" \
                          ${@SERVICE})
    else
      format.html { render :new }
      format.json { render json: @ticket.errors, status: :unprocessable_entity }
    end
  end
  end
  
  # Use callbacks to share common setup or constraints between actions.
  def set_ticket
    @ticket = Ticket.find(params[:id])
  end
  
  # Never trust parameters from the scary internet, only allow the white list through.
  def ticket_params
    params.require(:ticket).permit(:name, :seat_id_seq, :address, :price_paid, :email_address,:attachment)
  end
  </code></pre>
  
  <p>whenever I click on the submit button, I see this in the log file:</p>
  
  <pre><code>Started POST "/sparcformpages" for ::1 at 2016-12-21 14:42:32 -0500
  Processing by SparcformpagesController#create as HTML
  Parameters: {"utf8"=&gt;"✓",   "authenticity_token"=&gt;"8p9NtPkUn9C+YuG3hMQ1LgnKL/8BxEzXHCnV4S7qRNBd8Spwr+jX9Y7E3 qbLok/K4fx/mHFf7Eljo/2UqkHF3w==", 
  "sparcformpage"=&gt;{"record_id"=&gt;"333", "BSMType"=&gt;"Study Design/Development", "Description"=&gt;"", 
  "purposeOfStudy"=&gt;"Government Grant Submission", "purposeOfOtherStudy"=&gt;"", "studyDesignSupport"=&gt;"", 
  "grantNumber"=&gt;"", "purposeOfDataAnalysis"=&gt;"Manuscript Development", "purposeOfOtherAnalysis"=&gt;"", 
  "typesofAnalysis"=&gt;"Analysis Plan Development", "otherTypesOfAnalysis"=&gt;"", "scopeOfAnalyticSupport"=&gt;"", 
  "researchType"=&gt;"Human", "IRBNumber"=&gt;"", "IACUCNumber"=&gt;"", "completionDate"=&gt;"", "projectFundingStatus"=&gt;"External funding with built-in BSM support", 
  "chargeforStudy"=&gt;"", "chargeForDataAnalysis"=&gt;"", "chargeForOtherEffort"=&gt;"", "projectTrainee"=&gt;"Yes", "primaryMentor"=&gt;"", "emailAddress"=&gt;"",
   "alreadyCorresponded"=&gt;"Yes", "preferenceOffaculty"=&gt;"Dr. Marni Jacobs", "preferenceOfdataAnalyst"=&gt;"Yao Cheng", 
  "statusOfCollaboration"=&gt;"ongoing"}, 
  "commit"=&gt;"Create Sparcformpage"}
  </code></pre>