Brian Gilbank

Joined

9,030 Experience
61 Lessons Completed
3 Questions Solved

Activity

Posted in Hotwire Not Working Inside of Namespace

This seems like an easy fix, but I am not sure why its not working. I have an admin dashboard using Hotwire, but I can't seem to create records for my gym model (There are no errors, and it will work when I refresh). I can create records outside the namespace using the same model though, and using the same setup as below.

Do I need to pass the namespace in with the dom_id for Hotwire to work? Or is it an issue with the form_with namespace?

example namespace form
<%= form_with(model: [:dashboard, gym]) do |f| %>
 *fields
<% end %>

_gym.html.erb
<div id="<%= dom_id gym %>" class="card">
 *content
</div>

show.html.erb
<%= render @gym %>

Posted in How to write System Tests in Rails Discussion

For anyone using i18n you can do something like this:

require "application_system_test_case"

class AccountsTest < ApplicationSystemTestCase
  test "Can register for an account" do
    visit new_account_registration_path

    assert_difference("Account.count") do
      fill_in I18n.t("rnew.name"), with: "Tom Hanks"
      fill_in I18n.t("rnew.email"), with: "thanks@gmail.com"
      fill_in I18n.t("rnew.company"), with: "Cast Away"
      fill_in I18n.t("rnew.password"), with: "password850$"
      fill_in I18n.t("rnew.password_confirm"), with: "password850$"

      click_button I18n.t("rnew.register")
    end
  end
end

Posted in Bulk Operations in Rails Discussion

I am trying to make this work with rails request.js but not having much luck.

My flash partial renders in the terminal, but there's no content or message. Not sure what is going on. I am not re-directing after create, so do I need to use flash.now somehow?

Posted in How to use Rails Request.js Discussion

Hey Chris - How would you re-render a partial after publish/unpublish? Add a turbo frame tag to the partial? I want to re-render the edit page.

Posted in How to use Hotwire in Rails Discussion

I can't get any of my delete links to work, has this happened to anyone else?

Posted in Rails for Beginners Part 17: Login Form Discussion

Yes I know. I meant be able to login with either at the same time, similar to how you do it with Devise. https://github.com/heartcombo/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address

Posted in Rails for Beginners Part 17: Login Form Discussion

It would be great to show how to do login with both username and email as well.

Posted in How to use Devise with Hotwire & Turbo.js Discussion

Hey Chris - If we are still using Webpacker, we just need to change data-turbolinks-track to data-turbo-track in our layout files? In your episode repo, you still have it as turbolinks.

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbo-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbo-track': 'reload' %>

<%= turbo_include_tags %>

<%= stimulus_include_tags %> if we want to use stimulus in webpacker?

Posted in How do I search Action Text with Ransack?

Thanks, I will play around with it and see what I can figure out.

Posted in How do I search Action Text with Ransack?

Thank you! I am now getting duplicates in my searches though. Did that happen to you?

Posted in How to Add Pagination with Pagy Discussion

If we are counting records, ie. <%= index + 1%> how can we keep the count going when we we navigate to the next page? Currently my next page starts at 1 again.

Posted in Skipping Devise Confirmation for Stripe Signup

Hi Chris - How could I skip the Devise confirmation if a user is signing up to pay with Stripe?

I am following this video on your stripe course: https://courses.gorails.com/courses/payments-with-rails-master-class/152586-subscriptions-with-stripe-billing/451458-3-4-new-subscription-form

I was hoping I could do something like below.

class Users::RegistrationsController < Devise::RegistrationsController
invisible_captcha only: [:create], honeypot: :telephone, scope: :user, on_spam: :return_succeded

def create
super
if @user.persisted?
UserMailer.newuser_email(@user).deliver
end
if @user.persisted? && current_user.subscribed?
@user.skip_confirmation!
@user.confirm
end
end

end

Thanks
Brian

Posted in Action Text Colours & More Heading Options

Hey Chris - Is it possible to add a colour picker to action text, i.e. select some text and change its colour? Seems like a basic thing that should be included. It would be great if there were more heading options too. Maybe it will get an update because of hey.com?

Posted in Iterating using css grid

I had to add partial and it worked. Cheers,

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

Posted in Iterating using css grid

Hmm, still throwing the same error.

Posted in Iterating using css grid

I had it originally in a partial, but it was throwing an error for undefined local variable or method for gym.

<% if gym.image.present? %>

Posted in Iterating using css grid

Omg! I will get this one day. Thanks again.

Posted in Iterating using css grid

it's not stopping at 3 when it counts, eg

def index
  @q = Gym.ransack(params[:q]) 
  @gyms = @q.result.includes(:province).page(params[:page]).order("created_at DESC").paginate(:page => params[:page], :per_page => 18)
end

Posted in Iterating using css grid

Hey Chris - Just a follow up on this question. I am seeing a bunch of duplicate entries: https://gympass.ca/fitness-facilities for some reason?

<div class="clubs__index">
      <% @gyms.each_slice(3) do |gyms| %>
       <% @gyms.each_with_index do |gym, index| %>
        <div class="clubs__index--<%= index + 1 %>">
         <%#= render 'gyms/card' %>
         <div class="card">
          <% if gym.image.present? %>
            <%= image_tag gym.image.url, class: 'card__image', alt: gym.gym_name, size: "700X500"  %>
          <% else %>
            <%= image_tag 'https://ficdn-files.ca/images/gympass/logo/default_club_image_index.jpg', class: 'card__image', loading: "lazy" %>
          <% end %>
          <h3 class="card__title"><%= gym.gym_name %></h3>
            <h5 class="card__address">
            <%= gym.gym_address.titleize %><br> 
            <%= gym.gym_city.titleize %> / <%= gym.province.name if gym.province %><br>
            <%= gym.gym_postal.insert(3, ' ').upcase %>
            </h5> 
            <p class="card__details">
            <span class="card__details--bold"><%= t("gyms_index.telephone") %></span>
            <%= number_to_phone(gym.gym_telephone, area_code: true ) %><br>
            <% if gym.ext.present? %>
              <span class="card__details--bold"><%= t("gyms_index.ext") %></span>
              <%= gym.ext  %><br>
              <% end  %>
            <% if gym.gym_email.present? %>
              <span class="card__details--bold"><%= t("gyms_index.email") %></span>
              <%= gym.gym_email.downcase %> 
            <% end %>
          </p>
          <p class="card__url">
            <% if gym.gym_website.present? %>
            <%= link_to url_for(gym.gym_website), target: '_blank' do  %>
            <%= truncate(gym.gym_website.downcase.try(:remove, /.*\/\//), :escape => false, :length => 44)  %>
            <% end %>
          <% end %>
          </p>
          <ul class="card__social">
            <% if gym.gym_facebook.present? %>
            <li class="card__social--items">
              <%= link_to gym.gym_facebook, target: '_blank' do %>
              <i class="card__social--icons fab fa-facebook-f"></i>
              <% end %>
            </li>
            <% end %>
            <% if gym.gym_twitter.present? %>
            <li class="card__social--items">
              <%= link_to gym.gym_twitter , target: '_blank' do %>
              <i class="card__social--icons fab fa-twitter"></i>
              <% end %>
            </li>
            <% end %>
            <% if gym.gym_instagram.present? %>
            <li class="card__social--items">
              <%= link_to gym.gym_instagram, target: '_blank' do %>
              <i class="card__social--icons fab fa-instagram"></i>
              <% end %>
            </li>
            <% end %>
            <% if gym.gym_youtube.present? %>
            <li class="card__social--items">
              <%= link_to gym.gym_youtube, target: '_blank' do %>
              <i class="card__social--icons fab fa-youtube"></i>
              <% end %>
            </li>
            <% end %>
          </ul>
          <% if logged_in? %>
          <ul class="card__admin">
            <li class="card__admin--items">
              <%= link_to 'View', gym, class: "link-padding" %>
            </li>
            <li class="card__admin--items">
              <%= link_to 'Edit', edit_gym_path(gym), class: "link-padding" %>
            </li>
            <li class="card__admin--items">
              <%= link_to 'Destroy', gym, method: :delete, data: { confirm: 'Are you sure?' }, class: "link-padding" %>
            </li>
          </ul>
          <% end %>                                       
        </div> <%# card %>

        </div>
       <% end %> <%# do block end %> 
      <% end %>

    </div>  <%# clubs index %>
logo Created with Sketch.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2022 GoRails, LLC. All rights reserved.