lundi 22 juillet 2019

Stock Data recommendations for cloning robin hood

I am currently trying to clone Robinhood for my full stack webapp dev project. And I was wondering if there's anyone out there that can give me a recommendation for a free API to use for stock and trading data to be used. And also a graphing library for Javascript that will be fitted for the project.

Please help! Thank you in advance!

I've been looking on Rapid API for some APIS such as Yahoo Finance, but because I'm a newbie I'm not sure what I need to look for exactly.

For graphs and charts I m considering Char.js

Redirect to the previous page(same page)with destroy method

I am creating a cancel order page where customers can click on the cancel button and the page will render "order canceled successfully" and stay on the cancel page with the button disabled. I've googled and searched through it still not too sure how to achieve that, please help thank you so much!

  def destroy

    order.cancel
    redirect_to order_path(order.shopify_id), notice: 'Order cancelled'


end

</div>
<%= link_to 'Cancel Here', order_path(@order.shopify_id), method: :delete, class: 'btn btn-danger ' %>


</div>


dimanche 21 juillet 2019

Mobility Gem translation, Take "en" default from stored json in database

i have used a mobility gem for translation and in database i am storing json like { "de": "Abc", "en": "Abc", "fr": "Abc" } so when i am passing "de" language to params then it is giving the Abc translated for de language but i wanna do that if language passed from params is not exist in above json then it should take "en" as default , so what can i do for that?

in model i have used below code:

  include LocaleExtension
  extend Mobility
  translates :restaurant_name, type: :string
  # and  i have stored above json in restaurant_name field in database.

samedi 20 juillet 2019

What's the meaning of :[]

I'm new to ruby on rails, there's a code something like:

personMap.try(:[], :name)

What's the meanning of :[] here?

jeudi 18 juillet 2019

How to use Basic128 (encryption/encoding) in my signature?

I am calling soap API's with X.509 certificate.

And receiving an error that i have to use Basic128 in the signature.

Here is my Signature:

def the_signature
        raise MissingCertificate, "Expected a private_key for signing" unless certs.private_key
        signed_info = at_xpath(@document, "//Envelope/Header/Security/Signature/SignedInfo")
        signed_info = signed_info ? canonicalize(signed_info) : ""
        signature = certs.private_key.sign(OpenSSL::Digest::SHA1.new, signed_info)
        Base64.encode64(signature).gsub("\n", '') 
end


How can i use Basic128 to solve the above problem?

Couldn't find Order in ruby on rails

I am trying to build a page to load order id but it threw back Couldn't find Order, can you help?

routes.rb get '/orders/cancellation', to: 'orders#cancel'

<h1>Preview & Cancel your order here</h1>
<div class="block">

  <h1> Order <%= @order.name %></h1>

  <div id="multiple-file-preview">
    <ul id="sortable">
      <div class="clear-both"></div>
    </ul>
  </div>
</div>

def cancel
    paginate_versions PaperTrail::Version.where(order_id: order.id).order(created_at: :desc)
    remote_versions_pagination
  end

def order
    @order ||= Order.find_by!(shopify_id: params[:id])
  end

mercredi 17 juillet 2019

validation failed in polymorphic association

When I do a migration I get the following error "ActiveRecord::RecordInvalid: Validation failed: Huntinganimals must exist"

I'm not sure where I would declare "huntinganimals".

class Picture < ApplicationRecord
  belongs_to :camera_model
  has_one :animals, :as =>:HuntingAnimals
end
class User < ApplicationRecord
    has_one :animals, :as =>:HuntingAnimals
end
class Animal < ApplicationRecord
  belongs_to :HuntingAnimals, :polymorphic => true
end


class CreateAnimals < ActiveRecord::Migration[5.2]
  def change
        create_table :animals do |t|
        t.references :HuntingAnimals, polymorphic: true
    end
  end
end