vendredi 28 juin 2019

Net::SMTPAuthenticationError (535 5.7.3 Authentication unsuccessful [PN1PR01CA0089.INDPRD01.PROD.OUTLOOK.COM] )

I have tested the the account using my mail client and everything seems to be working fine, but when I try to send through my Rails 4 app I get the error:

config.action_mailer.smtp_settings = {
address: "smtp.live.com",
port: 587,
domain: Rails.application.secrets.domain_name,
authentication: "login",
enable_starttls_auto: true,

#tls: true,
user_name: Rails.application.secrets.email_provider_username,
password: Rails.application.secrets.email_provider_password,
openssl_verify_mode: 'none'}

mercredi 26 juin 2019

I want to concatinate two values into a single string

i have two different values systolic and diastolic blood pressure readings in string, i just want when those two values come from front-end i'll just store them into a single string E.g if systolic ='120' and diastolic='80' i want it to be bp='120/80'

module Api module V1 module CheckinMachine class BpsController < ApplicationController include MachineError before_action :authenticate_user!

    def create
      raise BatteryNotFunctionalError if battery_functional?
      # user = User.find_by!(bp_machine_imei: params[:imei])
      health_reading = current.health_readings.create!(key: :blood_pressure, value: bp_value)
      Solera::PostActivityApi.call(user,
                                   bp,
                                   health_reading.solera_activities.new)
      head :ok
    rescue ActiveRecord::RecordNotFound => _e
      render_machine_error and return
    end

    def show
      puts params
    end

    private

    def bp
      {
        systolic_blood_pressure: params[:systolic],
        diastolic_blood_pressure: params[:diastolic]
      }
    end
  end
end

end end

That's what i have tried, what do i do to make it exactly like i want it to be

like bp = '120/80'

lundi 24 juin 2019

how to build a tick box with rails on view/index

I am trying to build a tick box section with rails on view/index,these are all the steps I've taken so far i know that i need to do something about routes.rb, can you help?

this is the view:

<table class="table table-hover">
      <thead>
        <tr>
          <th>Coupon</th>
          <th>first_name</th>
          <th>surname</th>
          <th>email</th>
          <th>occupation</th>
          <th>validation</th>
        </tr>
      </thead>
    <tbody>
      <% @scooties_coupons.each do |scooties_coupon| %>
        <tr>
          <td><%= scooties_coupon.coupon %></td>
          <td><%= scooties_coupon.first_name %></td>
          <td><%= scooties_coupon.surname %></td>
          <td><%= scooties_coupon.email %></td>
          <td><%= scooties_coupon.occupation %></td>
          <td><%= link_to "Mark as Valid", method: :patch %></td>
        </tr>
      <% end %>
    </tbody>
    </table>


(i know to mark as valid should use link to but i am not too sure where to link to)

 create_table "scooties_coupons", force: :cascade do |t|
    t.string "coupon"
    t.boolean "redeemed", default: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string "email"
    t.integer "expires_in"
    t.string "first_name"
    t.string "surname"
    t.string "oppcupation"
    t.string "occupation"
    t.boolean "validated"
    t.index ["coupon"], name: "index_scooties_coupons_on_coupon"
  end

(I've also created the validated as boolean in the db)

this is the controller:

def update

     @scooties_coupon = ScootiesCoupon.find(scooties_coupon_params)
     @scooties_coupon.update( scooties_coupon_params
    redirect_to scooties_coupons_new_path

  end


  def scooties_coupon_params
    params.require(:scooties_coupon).permit(:first_name, :surname, :email, :occupation)

  end

dimanche 23 juin 2019

How do I handle persistent currency switching throughout my app?

I support 3 currencies in my app GBP, JMD, USD.

When a user selects a currency on one page, it reloads the page and sets the session[:currency] variable accordingly. The challenge is, depending on the currency they select of the 3, the behavior isn't always predictable and the same.

I may have just been looking at this logic too long, but I can't figure out why it doesn't work and would love an extra pair of eyes.

So I started with this in my application_controller.rb:

unless params[:currency].blank?
  if params[:currency] != session[:currency] || session[:previous_currency].blank?
    session[:previous_currency] = session[:currency]
    session[:currency] = params[:currency] 
  end
else
  if session[:currency].blank?
    session[:currency] = 'JMD'
  end
end

That didn't really capture USD, GBP.

So that has since been modified to this:

unless params[:currency].blank? && session[:currency].blank?
  if (params[:currency].eql? "JMD") || (session[:currency].eql? "JMD")
    session[:currency] = 'JMD'
    session[:locale] = :en
    session[:previous_currency] = 'GBP'
  elsif (params[:currency].eql? "GBP") || (session[:currency].eql? "GBP")
    session[:locale] = :"en-GB"
  elsif (params[:currency].eql? "USD") || (session[:currency].eql? "USD")
    session[:locale] = :en
  elsif params[:currency] != session[:currency] || session[:previous_currency].blank?
    session[:previous_currency] = session[:currency]
    session[:currency] = params[:currency]
  end
else
  session[:currency] = 'JMD'
  session[:locale] = :en
end

The issue is this one doesn't work when I am going from any currency to GBP, and I can't quite figure out why.

What I mean is, say I change from USD to GBP. If I go to another page (say the homepage) it reverts to the default JMD currency. When I want it to stay GBP just like it does if I switch to USD and change pages everything stays in USD.

What am I missing?

lundi 17 juin 2019

possible to delete all rails session info for all users

I am working on a legacy Rails 3.2 app and would like to log everybody out and have their _app_session be reset with the secure flag set to true. It seems like either changing our session_store strategy to secure: true or config.force_ssl = true. Strangely only the latter seems to work correctly in Chrome.

The question is that it seems like the best way to log everyone one would be to remove their session variable and I tried this solution here https://stackoverflow.com/a/11422931/152825 of:

rake tmp:sessions:clear

but it didn't seem to work. Is there a better way to clear these session variables?

jeudi 13 juin 2019

get going to be executed query before execution on ActiveRecord::Base

I want to copy old_db.table data to new_db.table.

I used ActiveRecord::Base.connection.execute(sql) this method for executing my insertion query. That perfectly insert data to new_db.table . But I want to get the query before actual execution.

sql = "insert into `#{new_db}`.#{table} #{f} (select * from #{old_db}.#{table});"
ActiveRecord::Base.connection.execute(sql)

For example I want print "insert into new_db.table values(value1, value2, value3, ...)" something like this, the row-wise execution of my query. How can I do that?

how to add if statement in form with rails

I am trying to implement this logic into form based on the sku (where sku will determine the country and the country will determine the shipping option)

country = order&.shop&.country
    if (READY_FOR_SCHOOL_SKUS + STICKER_BOOK_SKUS).include?(product.sku)
      if country == "uk"
        shipping_option = ShippingOption.find_by(name: "RoyalMail48")
      else
        shipping_option = ShippingOption.find_by(name: "TPLP")
      end
      return shipping_option
    end
    if (DICTIONARY_SKUS + WORD_OF_DAY_SKUS).include?(product.sku)
      if country == "uk"
        shipping_option = ShippingOption.find_by(name: "RoyalMail48")
      else
        shipping_option = ShippingOption.find_by(name: "standard_3_to_10_days")
      end
      return shipping_option
    end
    if (RFS_STICKER_BOOK_SKUS + USA_SUBSCRIPTION_SKUS + UK_SUBSCRIPTION_SKUS).include?(product.sku)
      if country == "uk"
        shipping_option = ShippingOption.find_by(name: "dhl")
      else
        shipping_option = ShippingOption.find_by(name: "TPLP")
      end
      return shipping_option
    end

<% @product.product_shop_shipping_options.uniq(&:shop).each_with_index do |psso, i|%>
  <%= f.fields_for :product_shop_shipping_options, psso do |s| %>
    <%= s.label psso.shop.shopify_shop_name %>
    <%= s.hidden_field :shop_id %>
    <%= s.grouped_collection_select :shipping_option_id, @fulfilment_centres, :shipping_options, :name, :id, :name, {prompt: 'Select shipping option'}, { class: 'form-control'} %>
  <% end %>
<% end %>