Chris Oliver

Joined

248,110 Experience
19 Lessons Completed
272 Questions Solved

Activity

💪 This is awesome Nate! This is a great opportunity if anyone's interested in getting a bit of experience working with a team.

I said that and decided to look at the Pay gem and think I figured it out.

The Rakefile in that gem loads the Rakefile from the dummy app. That makes total sense.

APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)

I need to figure out what's up with the Rake tasks, but I've had to go cd test/dummy && rails db:schema:load to get it to load the db tasks for testing.

I'm pretty sure it's something small that's missing, but I haven't had a chance to look yet. If you figure out what's missing with the Rakefile, send me a PR! 😜

If you read the logs, you'll see it crashed while loading secrets.

/home/deploy/bane/shared/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/secrets.rb:24:in `parse'

So my guess is that you're missing secrets on your server or they're empty or not formatted correctly.

Yeah, we'll do DMs. 👍

They'll be very similar to before. Basically just a chatroom with a direct message flag like we did previously.

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

And glad it's been so helpful! This is the community I wish I had a long time ago, so that's great to hear!

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

Yeah, you'd want to change your DNS to point to the new IP once the site is ready. Before you do that, you can change the TTL down to the lowest time so your DNS records will only be cached for the minimum time making the new IP change happen quick.

With your database on another server, you won't have to migrate that so it should be a lot easier then. 👍 You can actually run both copies of the app at the same time and make sure they can connect to the db and then change the DNS as the final step.

You'll also want to make sure any SSL certs are copied over. Forgot about that too.

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

If you spun up a new server and deployed the app to it with Capistrano, really the only thing you'd need to move over are any file uploads and the database. You can dump the postgres database then upload and import it on the new machine. Same with the files. That would be really all there is to it.

Posted in Best way to grant a user specific permissions

@oomis, take a look at the Pundit episode. Since I wrote this, I've used the Pundit gem for authorization over CanCanCan. It's less confusing to me. https://gorails.com/episodes/authorization-with-pundit

Posted in User model guidance

Hey Stephen!

The way I do it in JumpstartRails.com is we have a single User everyone logs in as and they have multiple Accounts they're associated with.

Each account could have a type of Coach, Client, etc and they switch between them with a session cookie. When they switch, we use current_account to load the account and we could use that to determine if they should see Coach or Client views.

Yep, that's the built-in way. Sounds like your code doing the validation is strict about what type of object it is (a Hash) and that's the part that's not very Ruby-ish.

Ah, well you can always cast it to a hash with to_hash

It's the same. Strong params is just a Hash-like object so you don't have to do anything special to it. It's designed like that to work seamlessly but be secure.

Posted in Multitenancy with the Apartment gem Discussion

Not with Apartment since they're in separate schemas. If you do row-based multitenancy you can. Check out acts_as_tenant. That's what we use for JumpstartRails.com and it's a lot more flexible and scales better.

Posted in Adding Javascript to Rails 6

Webpacker doesn't make require available in the browser window, so you have to set that explicitly.

window.toastr = require('toastr')

Working example here for you: https://github.com/excid3/rails_toastr_example

Posted in Adding Javascript to Rails 6

Example code I forgot to paste:

def toastr_flash
  flash.each_with_object([]) do |(type, message), flash_messages|
    type = 'success' if type == 'notice'
    type = 'error' if type == 'alert'

    text = <<~EOF
      <script>
        document.addEventListener("turbolinks:load", function() {
          toastr.#{type}('#{message}', '', { closeButton: true, progressBar: true })
        });
      </script>
    EOF
    flash_messages << text.html_safe if message
  end.join("\n").html_safe
end

Posted in Adding Javascript to Rails 6

Hey Tom,

That would be giving you the error because Javascript with inline script tags (that your helper is generating) are executed immediately. It does not wait for your webpacker Javascript to finish loading toastr before it runs. Hence the error.

You will want to wrap your code in a turbolinks:load event so that it waits until Turbolinks is ready and all your JS is loaded before it executes.

Posted in Rails view_components

Yes! I've been meaning to get to that for a long time. ViewComponent is awesome.

Posted in Adding Javascript to Rails 6

Hey Tom,

You'll have to share what you've got so we can help. If you can push up a repo to github, that would be most helpful. Otherwise just post your steps to reproduce the issue and we'll get you sorted. 👍

Posted in URL Based multi tenancy

It's pretty simple and the only things that would affect it are possibly major Rails versions, so there aren't many changes to be made to it.

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

© 2020 GoRails, LLC. All rights reserved.