Chris Oliver

Joined

292,760 Experience
93 Lessons Completed
296 Questions Solved

Activity

Posted in New website design!

Oh simply because that's what TailwindUI was using and I wanted to ship the site instead of porting their examples to Stimulus. I forgot I still need to convert those!

Posted in Gem for making user groups

Typically I just create a model called Group and a model called GroupUser that keeps track of which user is in which groups.

No gems for it that I know of since everyone tends to implement it differently.

Pundit is great for handling permissions and Devise is great for authentication pieces. The Group and GroupUser models will let you connect the two.

Hey Camilla,

I almost always use the Devise wiki page to not require the current password to update their account. That would make it so the user wouldn't have to know their password to update.

And this would make for a fantastic screencast... 😎

One trick I like is using signed GlobalIDs. This way you can reference any model. Your form could list all the guests and employees and submit their SGID over to the booking to be transformed to the proper record.

They must be signed global IDs to prevent tampering though.

Definitely looks like a good solution if you can't use Javascript. No Javascript is sure going to cause a lot of frustrations for every other feature.

Generally for staging, you can just deploy the app to a single server to save money compared to the production fully load balanced cluster.

Posted in CRUD on attribute in N/N join table

You should loop through @user.user_items.includes(:item) instead so you can access the quantity without an extra query. The includes will load the items records efficiently so you aren't doing any N+1 queries.

Posted in CRUD on attribute in N/N join table

has_and_belongs_to_many does not allow you to access the join table, and therefore it's very rarely used.

Instead, you just want to define a has_many :through association.

class User
  has_many :user_items
  has_many :items, through: :user_items
end

class UserItem
  belongs_to :user
  belongs_to :item
end

class Item
  has_many :user_items
  has_many :users, through: :user_items
end

This way you can interact with the join table and add things like quantity.

Posted in Refreshing the page with form errors

Turbolinks is getting a major update now that HEY.com was released and I believe is going to fix this. One of their main improvements was to fix the forms.

Posted in Login with Facebook Discussion

There are easily like 100+ OAuth providers so we just have a few of the most popular ones built-in and made it easy for you to add any of the other available ones.

Posted in Login with Facebook Discussion

Hah, you beat me to answering it. I was going to say, we made it so that by default any omniauth libraries you add will be automatically handled by the callbacks controller so there's nothing to do unless you want to extend the integration.

Posted in How do I override the default link_to helper?

Great! Congrats on your first gem. 🎉

There's nothing special you need to do for deploying Webpacker with Capistrano as it's built-in to the Rails assets:precompile step. The only thing you need to do is make sure that NodeJS is installed and in your PATH when deploying.

You don't want to install NVM as the root user. It should be on the deploy user, same as rbenv. Your code always runs and deploys under the deploy user so you want to avoid root.

Posted in How do I override the default link_to helper?

I wouldn't override it, just add your new method and call it like safe_link_to.

Roughly something like this:

def safe_link_to(name = nil, options = nil, html_options = nil, &block)
  link_to(name, options, html_options, &block)
end

Then you can add your call to sanitize in there. I think you'd probably wrap options with the sanitize call most likely.

Posted in User logoff/clear session

Hey Dainius,

That looks like it would work fine to me. What's happening? You're still logged in after it redirects you?

You're going to want to change that to a DELETE request though, otherwise people can do semi-malicious things and log you out from any website just by making your browser load that URL.

Jesus, yup all the concepts are still the same for Rails 6.

The only change is that Javascript is now primarily written in the app/javascript folder using Webpacker instead of the asset pipeline in app/assets/javascripts. Still works about the same, but has a lot of new features.

Stylesheets still go in app/assets/stylesheets, same as before.

Filled this out a while back. Thanks for putting this together. Always love seeing the results here. 👍

This is awesome Martin!

Rails calls them "routes", not links. That's what you'll want to search for and read up on. 👍

https://guides.rubyonrails.org/routing.html