Chris Oliver


238,210 Experience
17 Lessons Completed
260 Questions Solved


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

class UserItem
  belongs_to :user
  belongs_to :item

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

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 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)

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. 👍

Posted in How to build a wizard

I like that idea. Honestly for most wizard things, I have used Wicked ( just about every time. It controls the steps for you and stores them on the model so it remembers the location and everything.

I'd probably still recommend Wicked, but it'd be great to do a basic walkthrough of how you'd implement this from scratch too.

I would pass in the search params into the employee show URL so you can have a link back to the search results that includes the same params.

Ah sorry I was confused. I was thinking of the "active" state of a link / tab / etc.

He's referring to active like the &:active { css selector.

You either need to define it or just have it add the classes you want to the list. "Active" means very different things depending on your UI design.

I either do it inline or in a helper.

Here's an inline example:

<%= link_to "Account", account_path, class: ["blue", ("active" if request.path == account_path)]
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.