Now that we have the 15th of last month saved as the_15th_of_last_month and the most_recent_episode_publishing_date, we can compare them to know if this episodes is more recent than the last 15th of the month:
This means that our most most_recent_episode_publishing_date was published before the 15th of last month. As I only want episodes published in between the last 15th and today, I’ll not add this to the Invoice association.
The logic can be flipped around however you want to use this tool. Enjoy!
DEPRECATION WARNING: Single arity template handlers are deprecated. Template handlers must
now accept two parameters, the view object and the source for the view object.
>> Coffee::Rails::TemplateHandler.call(template, source)
(called from at /Users/MediocreManta/Desktop/freedom_podcasting/Rakefile:6)
This was an error I encountered while upgrading my application from Rails 5.2 to Rails 6.0. I found the fix on this Github page, but I thought I’d write it out here to make it a bit clearer for the young programmers out there.
To fix it, I upgraded the coffee-rails by doing the following:
Change gem 'coffee-rails', '~> 4.2'` to `gem 'coffee-rails', '~> 5.0.0'
When first trying to get an understanding of polymorphic associations in Rails, I was completely lost. At this point in my learning curve, polymorphic associations are a high-level concept in Rails which allows the programmer to reuse a single model to be useful for other models. It’s difficult to describe without an example. So… here we go.
An example of a polymorphic association is as follows. Let’s say you’re building a sports history database. Baseball players and basketball players are both athletes, but you want to be able to keep the baseballers separate from the basketballers. One way to do that is to create an Athletes model.
The Athlete model would be a way to tie the sports together.
Coding The Polymorphic Association
This requires a migration where we connect the athletes with the sports they play:
rails g migration AddSportToAthlete sport_id:integer sport_type:string
First we set the polymorphic association model:
class Athlete < ApplicationRecord
belongs_to :sport, polymorphic: true
Then we assign that association to the baseballers and the basketballers:
class Baseballer < ApplicationRecord
has_many :athletes, as: :sport
class Basketballer < ApplicationRecord
has_many :athletes, as: :sport
I’m deep diving into Ruby on Rails this week. One of the things I find interesting is how the scaffolding creates new parts of a Rails app. This is a helpful tool for understanding the stack so I’m stepping through it looking at the changes made which we can see better with git.
Below is a step by step view of the files created when developing a new Rails App.
Note: git changes do NOT note that when generating a new controller, Rails also generates an empty views folder. This is an important thing to be aware of as your view templates will go here related to your new controller.
appName => bin/rails generate model name_of_model title:string body:text slug:string