mardi 17 janvier 2023

Convert date string to Date where Day is missing

I know i can use to_date or parse to convert a string to a date in rails, but how do i convert to a date if the string is of the format "01-2018", where 01 is the month (January) and the day is missing ? Must be simple but i am having trouble doing it.

Trying it returns unexpected results, I am guessing because the day is missing:

3.0.2 :004 > Date.parse(x)  => Sun, 01 Jan 2023
3.0.2 :005 > x  => "01-2018"
3.0.2 :006 > x.to_date  => Sun, 01 Jan 2023

I guess i can prefix the string with sth like "01-", but is there a better way?

lundi 16 janvier 2023

Ruby run project while error how can ı solve this problem

Hi ı wanna run ruby project.I write rails server -e development but ı get an error

/home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/activesupport-3.2.9/lib/active_support/values/time_zone.rb:270: warning: circular argument reference - now Traceback (most recent call last): 13: from script/rails:6:in ' 12: from script/rails:6:in require' 11: from /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/railties-3.2.9/lib/rails/commands.rb:50:in <top (required)>' 10: from /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/railties-3.2.9/lib/rails/commands.rb:50:in tap' 9: from /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/railties-3.2.9/lib/rails/commands.rb:53:in block in <top (required)>' 8: from /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/railties-3.2.9/lib/rails/commands.rb:53:in require' 7: from /home/deployer/apps/isg/20220314091757/config/application.rb:15:in <top (required)>' 6: from /usr/lib/ruby/vendor_ruby/bundler.rb:114:in require' 5: from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:65:in require' 4: from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:65:in each' 3: from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:76:in block in require' 2: from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:76:in each' 1: from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:80:in block (2 levels) in require' /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:84:in rescue in block (2 levels) in require': There was an error while trying to load the gem 'delayed_job_active_record'. (Bundler::GemRequireError) Gem Load Error is: undefined method yaml_as' for ActiveRecord::Base:Class Did you mean? yaml_tag Backtrace for gem load error is: /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/activerecord-3.2.9/lib/active_record/dynamic_matchers.rb:50:in method_missing' /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/delayed_job-4.0.4/lib/delayed/serialization/active_record.rb:4:in class:Base' /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/delayed_job-4.0.4/lib/delayed/serialization/active_record.rb:3:in <module:ActiveRecord>' /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/delayed_job-4.0.4/lib/delayed/serialization/active_record.rb:2:in <top (required)>' /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in require' /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in block in require' /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in load_dependency' /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in require' /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/delayed_job-4.0.4/lib/delayed/worker.rb:64:in backend=' /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/delayed_job_active_record-4.0.2/lib/delayed_job_active_record.rb:5:in <top (required)>' /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:81:in require' /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:81:in block (2 levels) in require' /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:76:in each' /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:76:in block in require' /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:65:in each' /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:65:in require' /usr/lib/ruby/vendor_ruby/bundler.rb:114:in require' /home/deployer/apps/isg/20220314091757/config/application.rb:15:in <top (required)>' /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/railties-3.2.9/lib/rails/commands.rb:53:in require' /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/railties-3.2.9/lib/rails/commands.rb:53:in block in <top (required)>' /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/railties-3.2.9/lib/rails/commands.rb:50:in tap' /home/deployer/apps/isg/20220314091757/vendor/bundle/ruby/2.5.0/gems/railties-3.2.9/lib/rails/commands.rb:50:in <top (required)>' script/rails:6:in require' script/rails:6:in ' Bundler Error Backtrace:`

I install node js but doesnt work

Got the error File type is not supported when uploading a file in ruby on rails

 url = URI("https://api.podium.com/v4/messages/attachment")
      https = Net::HTTP.new(url.host, url.port)
      https.use_ssl = true
      request = Net::HTTP::Post.new(url)
      request["Content-Type"] = "multipart/form-data"
      request["Authorization"] = "Bearer #{access_token}"
      form_data = [["attachment",File.open('D:\proj\v5\ap\fl\Screenshot (1).png')],['data', "#{request_data}"]]
      request.set_form(form_data, 'multipart/form-data')
      response = https.request(request)
      response_body = JSON.parse(response.body)
      if response.code == '200' || response.code == '201'
          return response_body,'success'
      else
           return response_body,"#{response.message}"
      end
      rescue Exception => ex
        return ex,'Exception'
     end

** When i am sending the request i got the error like

{"code"=>"invalid_request_values", "message"=>"File type is not supported.", "moreInfo"=>"https://ift.tt/ahE7HgF} **

jeudi 12 janvier 2023

ActiveRecord::StatementInvalid in Summaries#index

PG::UndefinedColumn: ERROR: column summaries.user does not exist LINE 1: SELECT "summaries".* FROM "summaries" WHERE "summaries"."use...

I'm trying to make a view restriction, where only the admin can see all the records in an app

TypeError: superclass must be a Class (Module given)

I have a class which inherits another class

Class A
end

Class A::B < A
end

I am trying to write specs for class B by describing it as:

describe A::B, type: :class do
 #some test here
end

But i get this error: TypeError: superclass must be a Class (Module given) on spec file'd describe line. How can i fix this?

vendredi 6 janvier 2023

Can i use variables in Rails link_to method?

Can i use variable for Rails link_to helper for making different link with variables?

For example, <%= link_to users, users_path %> I have link like this,

And i'd like to change this url with variable examples

So i changed url like this, <%= link_to users, "#{examples}_path" %> This not worked because of whole string change to url.

How can i change my link_to for use this with different variable for DRY codes?

mercredi 4 janvier 2023

omniauth: (linkedin) Authentication failure! invalid_credentials

Request phase initiated. Started GET "/users/auth/linkedin/callback?code=...&state=..." for 127.0.0.1 at 2022-09-14 20:50:20 +0200 D, [2022-09-14T20:50:20.537126 #37240] DEBUG -- omniauth: (linkedin) Callback phase initiated. E, [2022-09-14T20:50:21.021252 #37240] ERROR -- omniauth: (linkedin) Authentication failure! invalid_credentials: OAuth2::Error, invalid_request: A required parameter "client_secret" is missing {"error":"invalid_request","error_description":"A required parameter \"client_secret\" is missing"} Processing by Users::OmniauthCallbacksController#failure as HTML

ruby version 3.2.0 rails version 7.0.4

gem 'omniauth' gem 'omniauth-linkedin-oauth2'