David McDonald

Joined

460 Experience
2 Lessons Completed
0 Questions Solved

Activity

Posted in Law of Demeter - Question

Thanks that's very helpful I'll read it. Perhaps I'll go with the follow that seems to be inbetween the two?

I'm going to think on your version and this one a little more. Try and work out the pros/cons to placing them in both of their places. Thanks again!

class Report < ApplicationRecord
  has_many :evaluations

  def accuracy
    evaluations.accuracy
  end
end
class Evaluation < ApplicationRecord
  belongs_to :report
  belongs_to :skill

  def self.accuracy
    joins(:skill).find_by(skills: { code: "ACC" })
  end
end
class Skill < ApplicationRecord
  has_many :evaluations
end

Posted in Law of Demeter - Question

Thanks! I appreciate that note - it is cleaner. As I'm tryng to apply it to the single method call I've come up with this, but it's currently not giving me the same result as the older code.

class Report < ApplicationRecord
  has_many :evaluations

  def accuracy
    evaluations.accuracy
  end
end
class Evaluation < ApplicationRecord
  belongs_to :report
  belongs_to :skill

 delegate :accuracy, to: :skill

end
class Skill < ApplicationRecord
  has_many :evaluations

 def self.accuracy
   find_by(code: "ACC")
 end

end

Posted in Law of Demeter - Question

Had a question about how to refactor some of my code. I've been reading some books AntiPatterns & Refactoring. Given the code block here, should the method here be in Evaluation or Skill? If I'm following the "rule" in AntiPatterns for using only one dot, and reports is knowing too much about skills and evaluations... how would this look like if I wanted to retrieve the accuracy evaluation from my report object?

class Report < ApplicationRecord
  has_many :evaluations
  def accuracy
    evaluations.joins(:skill).where('skills.code = (?)', 'ACC').try(:first)
  end
end
class Evaluation < ApplicationRecord
  belongs_to :report
  belongs_to :skill
end
class Skill < ApplicationRecord
  has_many :evaluations
end

Posted in How can I switch from RVM to RBENV?

found this guide, worked for me on development - haven't tried on production yet.

https://gist.github.com/traumverloren/fa5c30056319992c4dab

Hey I followed the deploying guide for Ubuntu 20.04 LTS. When deploying my application I get the following error. Googling around I haven't been able to locate any leads on what to do... anyone have a suggestion to try? Thanks!

My current project I'm attempting to deploy is Rails 5.1.6 as well.

Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as [email protected]: rake exit status: 1
rake stdout: Nothing written
rake stderr: rake aborted!
NoMethodError: undefined method `deep_symbolize_keys' for #<String:0x0000559b3df3afb0>
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/secrets.rb:29:in `block in parse'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/secrets.rb:24:in `each'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/secrets.rb:24:in `each_with_object'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/secrets.rb:24:in `parse'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/application.rb:391:in `secrets'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/application.rb:172:in `key_generator'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/globalid-0.4.1/lib/global_id/railtie.rb:26:in `block (2 levels) in <class:Railtie>'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:67:in `block in execute_hook'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:60:in `with_execution_control'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:65:in `execute_hook'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:50:in `block in run_load_hooks'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:49:in `each'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:49:in `run_load_hooks'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/application/finisher.rb:73:in `block in <module:Finisher>'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `instance_exec'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `run'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/initializable.rb:59:in `block in run_initializers'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/initializable.rb:58:in `run_initializers'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/application.rb:353:in `initialize!'
/home/deploy/bane/releases/20200806170130/config/environment.rb:5:in `<top (required)>'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `block in require'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:258:in `load_dependency'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/application.rb:329:in `require_environment!'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/application.rb:445:in `block in run_tasks_blocks'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
/home/deploy/.rbenv/versions/2.6.1/bin/bundle:23:in `load'
/home/deploy/.rbenv/versions/2.6.1/bin/bundle:23:in `<main>'
Tasks: TOP => environment
(See full trace by running task with --trace)

Posted in How can I switch from RVM to RBENV?

I have followed the deployment capistrano guide in the past on GoRails. At the time I setup using RVM... what are the steps to switching from RVM to RBENV? I think I would need to changeover on my development machine and my production machine and then switch over the gems in my Gemfile.

I'm not sure how to (1) Change over from one to the other, (2) if there are any additional steps I'm not thinking of...

Posted in What's a good way for upgrading a server?

Thanks Chris! I think that's how I assume it will go as well. The database is on it's on SQL Server, also great point about the uploads I forgot about that. What about the server's ip address? Would I essentially setup the other server and then just point my domain name to the new ip address? Your website has been very helpful in so many ways - and the quick responses and such are really amazing. Thanks so much I'm very happy to be a subscriber!

Posted in What's a good way for upgrading a server?

I have an internal application that is running fine now, but I need to upgrade the version of Ubuntu Server on it. I have put this off wayyyy too long. Essentially I have a "VMWare box" on the company's network that has my current Ubuntu Server that's still (embarrassingly) running 14.04 LTS. I have been deploying updates using the Capistrano guide found here at Go Rails.

My approach now was going to be for my IT person to setup a new server with Ubuntu 20.04 LTS and I would use the Rails guide here at Go Rails to setup a new server and deploy to it. After that I'm not sure what the best way would be to flip over the servers to have a, as much as possible, seamless transition. Anyone have any recommendations or things to look out for?

Sidenote, I was told by someone else that Docker would greatly simplify my life in this regard. While I am more than happy to explore that next I just want to get things upgraded and then I can look into some solution like that next. Thanks!

I wanted to generate a pair of partials. My approach is prerhaps flawed, but I was generating the same "id" for both partials when doing the replace for "NEW_RECORD". The way I managed to get around that was...

(my apologies I don't know how to add code block here...)

content = this.templateTarget.innerHTML.replace(/NEW_RECORD/g, Math.floor(new Date().valueOf() * Math.random())).replace(/NEW_SECOND_RECORD/g, Math.floor(new Date().valueOf() * Math.random()))

Perhaps this is helpful to anyone else that comes across this post.

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2021 GoRails, LLC. All rights reserved.