Chris Oliver


248,110 Experience
19 Lessons Completed
272 Questions Solved


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

Hey Fahad,

Try using this gem to add ActiveStorage support instead:

Posted in Iterating using css grid

Yeah, you want to pass it in as a local variable like so:

<%= render 'gyms/card', locals: { gym: gym, index: index } %>

Partials need locals passed in so it can assign those variables and use them the same way as the parent template was.

Posted in Iterating using css grid

One thing that can help is extracting out things into partials, that way you can see your code a bit clearer. Looks like you were on that path, but it's commented out. I try and do that from the very beginning and that makes sure I have my loops setup correctly.

Posted in Iterating using css grid

You've got 18 per page in your pagination. Then you're not using the slice you defined.

<% @gyms.each_slice(3) do |gyms| %>
  <% @gyms.each_with_index do |gym, index| %>

You see the second line where you're using @gyms a second time? That should be gyms

You're accidentally looping through each group of 3, then rendering all 18 for each of those groups. 😜

Posted in Subscriptions with Stripe Discussion

I've turned it into a separate course since Stripe changes so much and it's hard to maintain these videos.

Posted in Iterating using css grid

Tailwind isn't your typical framework. It's just classes that wrap like one line of CSS so you'll end up learning CSS really quickly and better this way I've noticed. That's how I taught myself grid in the last month actually.

Posted in Iterating using css grid

And actually, if I were using TailwindCSS for CSS grid, I would do the following and set the grid to 3 columns.

<div class="grid grid-cols-3">
  <% posts.each_with_index do |post, index| %>
      <%= post.title %>
  <% end %>

Posted in Iterating using css grid

Yep, makes sense. You need to slice the array into groups of 3, then loop through each one of those instead.

<% @posts.each_slice(3) do |posts| %>
  <% posts.each_with_index do |post, index| %>
    <div class="grid-<%= index + 1%>">
      <%= post.title %>
  <% end %>
<% end %>

Posted in Jekyll as a support page?

If you compiled them so they output to public/support that would probably do the trick.

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.