Chris Oliver

Joined

290,710 Experience
86 Lessons Completed
298 Questions Solved

Activity

Posted in Time in top left corner chrome extentsion

The timing widget on the page is Rack Mini Profiler: https://github.com/MiniProfiler/rack-mini-profiler

You can query the database if you are using the database delivery method.

Posted in How to initialize datepicker in stimulus controller?

Turbo:load runs when a page loads, not a frame. It's the same as the old turbolinks event. Frames are independent from page views which means you need to setup a Stimulus controller instead.

Check out stimulus-flatpickr and you won't have to build anything. 👍

https://github.com/adrienpoly/stimulus-flatpickr

No screencast yet, but their readme is pretty well documented. 👍

Posted in Rails 6 basics issue

Rails comes with the webdrivers gem now and you should use that now. It makes things a lot easier. In fact, there's nothing you have to setup other than just installing the gem (unless you want to customize it).

https://github.com/titusfortner/webdrivers

Posted in get data from once working db

You can run rails db:migrate to run all the migrations in the db/migrate folder. That will make sure all your database tables are created. It won't restore any data, just the tables and columns though.

rails db:seed will populate the database with example records (assuming there is code to create records in db/seeds.rb. 👍

Posted in Upgrade strategy from Rails 4.2.4 to 6.0.3.4?

Upgrading from 4.2 to 5.2 to 6.1 would certainly give you some thorough testing of the changes and would be a bit less daunting.

You can probably upgrade straight to 6.1, but you'll want to go through all the upgrade notes to make sure you know of all the changes between. Things like belongs_to being required by default might catch you off guard if you skip straight to the latest version and miss that in the Rails 5 release notes. 😅

Hey Daniel,

There's a concept called OEmbed that was designed to let services define their own embed codes. You just give their site the URL you want to embed and then send you JSON back on how to embed it.

There's a Ruby library for it that is pretty useful: https://github.com/ruby-oembed/ruby-oembed

This is the approach I'm using on Jumpstart Pro to provide embed codes in ActionText.

Posted in RSpec w/capybara vs Mini Test

@sweedledee there's not a lot of good examples out there! I did a lot of the Testing Rails series in Minitest which is a start. The Rails test suite is where I learned a good bit if you feel like digging through the repository.

I bought betterminitest.com to document common use cases and need to start putting that site together!

That was the first thing I did when I added Noticed to JumpstartRails.com :)

Conceptually all you need to do is:

  1. Add a dropdown for notifications
  2. Setup notifications to use Database + Websocket delivery methods
  3. Have Javascript listen to the websocket and insert the notification when a new one is received
  4. Add the red dot to the HTML
  5. Remove the red dot when opening the dropdown

Posted in Rails latest (6.1.1) with Ruby latest (3.0.0)

If I'm looking for the template from a brand new Rails app, I'll actually open the github repo for Rails and find the template in there.

For example: https://github.com/rails/rails/blob/main/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt

And I imagine you'd get answers quickest on StackOverflow. I always forget about the Rails discourse. I need to poke around on there more regularly.

Don't forget the GoRails slack if you're a subscriber! There's always people around to help there.

I spent a lot of time just reading source code for Rails and trying to apply those approaches to my own code.

Most of the deep knowledge is just Ruby, not Rails. I should mention, I made a course last year that digs into all these things that I wish I knew about Ruby when I was learning Rails. Explains a lot of approaches that you'll see in gems like Rails. Took me years to learn all this stuff, so I thought it'd be good to put it into a course. Might be worth checking out. https://courses.gorails.com/advanced-ruby-for-rails-devs

Posted in Multiple user types App design

Generally, the easiest is use 1 Devise model and separate models for the type of user. That way everyone uses the same sign in page.

Posted in Rails latest (6.1.1) with Ruby latest (3.0.0)

What glitches are you referring to?

Ruby 2.7 and Rails 6.1 are probably the best to go with for now I'd say.

Posted in Go Rails Youtube videos not loading

Strange, the Message Templates video plays fine for me, logged in and incognito. Maybe a browser extension or something blocking it?

Side note, the search is SLOW. I need to fix that.

You can't use include with a class. Remove that and reference the class directly like so:

class Licencia < ApplicationRecord
  validates_with Validators::LapseValidator
end

That should do the trick. 👍

It needs to be namespaced under Validators:

class Validators::LapseValidator < ActiveModel::Validator

Posted in Where do I put a custom validator for a model?

Generally, the concerns folder is for modules so it might get confusing in there but it should work.

You could also probably use app/models/validators/my_validator and include Validators::MyValidator now that I think about it.

I like this better than app/validators

Posted in Where do I put a custom validator for a model?

Any folders in app/ will be autoloaded, so you could create app/validators/my_validator.rb and include MyValidator in your model. Rails will autoload that and find it correctly. This is my preferred way of doing things usually.

Or you could put it in lib and require it as well.

Posted in What is Hotwire Strada?

No idea either! DHH said something that you can do 95% of mobile with Turbo and no Strada. Doesn't really explain much, but I'm real curious when it ships!