Chris Oliver

Joined

292,490 Experience
93 Lessons Completed
295 Questions Solved

Activity

You should try just paginating on the ActiveRecord association instead of the array.

def dashboard
    @gigs = current_user.gigs.page(params[:page]).per(4)
  end

Then in the view

<%= @gigs.each do |gig| %>
<% end %>

<%= paginate @gigs %>

Posted in Recording Building a Rails Based Accounting System

Love the idea! I've thought about doing something like this myself in the past, I just don't have the time. I love watching people stream this stuff on Twitch, so I'm sure other people will enjoy watching it too. 👍

Posted in How long will Rails 5 be supported?

Here's details on the support / maintenance policies for Rails. https://guides.rubyonrails.org/maintenance_policy.html

Only the latest release series will receive bug fixes. When enough bugs are fixed and its deemed worthy to release a new gem, this is the branch it happens from.

The current release series and the next most recent one will receive patches and new versions in case of a security issue.

For severe security issues all releases in the current major series, and also the last release in the previous major series will receive patches and new versions. The classification of the security issue is judged by the core team.

So that means Rails 5.2 will continue receiving security updates until Rails 6.1 is out. Rails 5.1 and earlier are no longer supported.

Hey Alex,

Have you set RAILS_ENV=staging on the server so it knows to run the staging env in production?

Awesome! I like when solutions are that easy. 🤘

Have you double checked to make sure you're indexing the account_id in ElasticSearch?

Posted in Model/concerns question

If you're calling title directly, then you're not calling your capitalize_title method. You would want to call the name method.

Ask and you shall receive! Here's the Uppy episode: https://gorails.com/episodes/uppy-with-active-storage

Posted in Model/concerns question

And your view is calling <%= @subject.name %>?

Posted in Setting background image from User uploaded asset

Hmm, I wonder why then the string was "" then. I assumed that's what it would do when there was no attachment.

Try just printing out the image_url on the page directly. Once you figure out what's missing there, then you can add it to the style attribute.

You can always throw a byebug onto the page so you can fiddle with it while it's rendering.

I think you just want something like:

def index
    query = params[User.where(account_id: Current.account)]  || "*" 

    args = {}
        args[:account_id] = Current.account.id
    args[:first_name] = params[:first_name] if params[:first_name].present?
    args[:languages] = params[:languages] if params[:languages].present?
    @users = User.search query, where: args,
                                aggs: {
                                  first_name: {},
                                  languages: {}
                               }
end

Posted in Setting background image from User uploaded asset

Well, it looks like you don't have an image attached. That will obviously only work if there is an image attached. 🧐

Posted in Setting background image from User uploaded asset

Assuming you're using ActiveStorage?

Should be like:

style="background: url('<%= image_url @creator.header_image %>');"

Posted in Model/concerns question

Great topic for me to record a screencast on.

Modules really just add methods to a class, so you can define both class and instance methods in the module and they're accessible as if they were defined in the class.

The module in your example adds an instance method, so you could call it inside any method in your class.

class Subject < ActiveRecord::Base
  include CapitalizeIt
  def name
    capitalize_title(self.title)
  end
end

If you were to add a class method in the module, then you could call it outside of a method because code that runs there is running inside the class, not an instance.

Methods like scope belongs_to and has_many are all examples of class methods.

Posted in Is there a acts_as_taggable gem that works on Rails 6?

acts_as_taggable_on works with Rails 6. I've been using it for ages, should do what you need. 👍

https://github.com/mbleigh/acts-as-taggable-on

Bruno,

Make sure you add the account_id in your search's where so it filters down. ElasticSearch is going to keep a separate indexed copy of your database, so when you search it, you need to apply the same types of filters as you would in your db queries.

Posted in Subscriptions with Stripe Discussion

That's up to you I'm pretty sure. They do allow you to configure their emails for various things like failed payments though. You can find all those email options in the Settings tab on Stripe.

Posted in Flatpickr with "Present" value as well.

Yep, and I don't know that you necessarily need the currently working boolean in the database. You can just add some methods in your model to delegate to the end_date column.

class Job
  def currently_working?
      !end_date?
    end
end

Then you can just use that method to set the checked attribute on the checkbox by default when editing.

Posted in Flatpickr with "Present" value as well.

Hey Gerard,

I would probably use Javascript to do two things when checked:

  1. Hide/show the end date field
  2. Clear the value for the date fields

Flatpickr write the selected value to a form field, so it can be submitted to the server. That's the field you'll want to clear out in the JS.

Then just make sure your end date field is marked as optional in your database so it can be null.

Posted in Login with Facebook Discussion

Hey Olivia! You might be able to add this to the User model so that they're always marked as "remember me" to extend the logins for as long as possible.

class User
  def remember_me
    true
  end
end

You can also configure Devise to have a longer cookie expiration which may help.