mardi 16 mars 2021

The rails program does not create a database even though typed the code correctly?

I am newbie with rails and trying to create a new rails program with postgre database by this command rails new freelancer --database=postgresql

I typed it very carefully and I hoped that I could have a rails program with a database which configure in a database.yml file (something as they said on internet which I can connect to postsql).

But, my problem is, when I open my database.yml, here it is

default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3

I do not know why it does not create the database for me as they said (they said that, if I use that command, the database could be created and will be created witl name freelancer_development which can be display in this file ?

Could you please give me some ideas ? Thank you very much for your comment.

Azure deploy Ruby not init

I can't upload app with git. When I access the app I got this message: No route registered for '/cancun.git'. Bash git push azure master

dimanche 14 mars 2021

TypeError no implicit conversion of Spree::Order into Hash

I am getting an error like this when I update the spree from 4.1 to 4.2 at the time of order creation.

Order Flow

  1. Add product into the cart
  2. Checkout product
  3. Address
  4. Shiping method
  5. Payment
  6. order completed and mail generated and this error displaying on success page TypeError no implicit conversion of Spree::Order into Hash

Cron-based terminal job doesn't start until screen unlocked (sometimes)

I have a cron job whose command line looks like:

30 5 * * * osascript -e 'tell application "Terminal" to do script "bash-script-file"'

FWIW the base script file sets some environment variables and then runs a Ruby program.

Prior to last week, most days this ran just fine, but occasionally (~ twice/month) it would hang until I either unlocked the screen or attached remotely to the system. At that time I would see a terminal screen with a message about new mail and a command line prompt with the bash-script-file on it. At that point, I could wait and the script would proceed to run normally. I have checked System Settings and the computer is set to sleep never. I'm not locking the screen (instead allowing it to go to sleep), and of course I have the screen saver locked, requiring a password to wake up.

Last week (about five days ago), I added a second cron job of the same form (running another bash script that started another Ruby program), and since then, both jobs have hung every day until I attached remotely. What is causing this? What can I do to resolve it?

tl;dr cron-scheduled terminal jobs are hanging until the screen unlocks.

vendredi 12 mars 2021

How to redirect to Not Found page if an invalid URL is passed on Active Admin?

I'm using ActiveAdmin gem in my Rails application. I have an Item resource in the ActiveAdmin. I have allowed all the actions except new.

actions :all, except: [:new]

But in the URL if explicitly passed /admin/items/new, it throwing an ActiveRecord::Not Found error as it taking new as an id. In the description of the error, it is showing "Couldn't find Item with 'id'=new. I want to redirect to 404 or Not found page if an invalid url is passed. Can someone help me with this? Thanks is advance!

jeudi 11 mars 2021

Información de curso de ruby [closed]

alguien me recomiende donde realizar un un curso de ruby que sea bueno, y que ya hayan hecho. gracias.

Find Specific value of hash using ruby

I am trying to extract the value of the skuPartNumber from the below hash

{:error_code=>0, :data=>{"@odata.context"=>"https://graph.microsoft.com/v1.0/$metadata#users('xyz.yxz@domain.com')/licenseDetails", "value"=>[{"id"=>"88sGumHGlkiNvM0ZAFLCmUmPksW6EvdIraMNdDo2AdU", "skuId"=>"c5928f49-12ba-48f7-ada3-0d743a3601d5", "skuPartNumber"=>"SKUPartName1", "servicePlans"=>[{"servicePlanId"=>"da792a53-cbc0-4184-a10d-e544dd34b3c1", "servicePlanName"=>"ONEDRIVE_BASIC", "provisioningStatus"=>"Success", "appliesTo"=>"Company"}, {"servicePlanId"=>"2bdbaf8f-738f-4ac7-9234-3c3ee2ce7d0f", "servicePlanName"=>"VISIOONLINE", "provisioningStatus"=>"Success", "appliesTo"=>"Company"}, {"servicePlanId"=>"113feb6c-3fe4-4440-bddc-54d774bf0318", "servicePlanName"=>"EXCHANGE_S_FOUNDATION", "provisioningStatus"=>"PendingProvisioning", "appliesTo"=>"Company"}, {"servicePlanId"=>"663a804f-1c30-4ff0-9915-9db84f0d1cea", "servicePlanName"=>"VISIO_CLIENT_SUBSCRIPTION", "provisioningStatus"=>"Success", "appliesTo"=>"Company"}]}, {"id"=>"88sGumHGlkiNvM0ZAFLCmZK4DfPpB-lHg3yAcn9G_T0", "skuId"=>"f30db892-07e9-47e9-837c-80727f46fd3d", "skuPartNumber"=>"SKUPartName2", "servicePlans"=>[{"servicePlanId"=>"113feb6c-3fe4-4440-bddc-54d774bf0318", "servicePlanName"=>"EXCHANGE_S_FOUNDATION", "provisioningStatus"=>"PendingProvisioning", "appliesTo"=>"Company"}, {"servicePlanId"=>"17ab22cd-a0b3-4536-910a-cb6eb12696c0", "servicePlanName"=>"DYN365_CDS_VIRAL", "provisioningStatus"=>"Success", "appliesTo"=>"Company"}, {"servicePlanId"=>"50e68c76-46c6-4674-81f9-75456511b170", "servicePlanName"=>"FLOW_P2_VIRAL", "provisioningStatus"=>"Success", "appliesTo"=>"Company"}]}]}}

However, I tried using result[:data]['value']['skuPartNumber'] and result in the error.

How can extract the skuPartNumber where the SkuPartNumber is equal to "skuPartName2" from the above hash.

I can extract values with

result[:data]['value'][0]['skuPartNumber']

But would like to get the result based on specific value by providing skuPartNumber

Any help would be helpful.

Thanks