Chris Oliver

Joined

292,890 Experience
93 Lessons Completed
295 Questions Solved

Activity

Posted in Ruby new

Hey Naldio,

The forums are a great place to ask questions. Just post your question along with code, any errors, stacktrace, and any other information you can include so we can do our best to help you! 🙌

Posted in Impossible to install Nokogiri - OSX Mojave 10.14.2

Getting closer it sounds like.

Try this and see if that helps.

gem install nokogiri -- --use-system-libraries --with-iconv-dir=$(brew --prefix libiconv) --with-xml2-include=$(brew --prefix libxml2)/include/libxml2

Alternatively, this one does the seame thing but doesn't use the libraries from homebrew in case the above fails:

gem install nokogiri -- --use-system-libraries=true --with-xml2-include="$(xcrun --show-sdk-path)"/usr/include/libxml2

According to Nokogiri's issues, they might have a fix coming out at some point soon so you won't have to do these workarounds. https://github.com/sparklemotion/nokogiri/pull/1851

Posted in Impossible to install Nokogiri - OSX Mojave 10.14.2

I'm still on High Sierra for my main computer, but let me open up Macbook which I upgraded.

My guess is that it's simply looking in the wrong folder still.

Did you try this line I had in the guide?

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

I noticed that the Nokogiri docs had a slightly different one.

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

Posted in Impossible to install Nokogiri - OSX Mojave 10.14.2

It says libxml2 is missing. so you might have just missed installing that dependency.

That's a simple brew install libxml2 to fix. 👍

Posted in Auto saving forms as they type.

First thing you'll need is a state column so when you click New, it creates a record in draft state so you can save all the changes to it.

Then I would just add some JS to submit the form via AJAX every once in a while. GMail does it after you stop typing for a few seconds, or you move your cursor out of the text box for example. The exact details on this probably depend a bit upon what your form looks like.

Saving the draft changes is really just submitting a PUT to the update action because the record's in draft state, you can just use the regular update. When you are ready to publish it, you can submit the new state or have a special publish action if you wanted to do more with it.

This would be a great screencast. 👍

Can you post your CommentsDatabale class for us as well?

Hey Victor,

Are you sure fetch_records isn't a method you're supposed to define in your class? From the examples for the datatables gem, it looks like you typically write that method yourself in the class.

You'll probably have to share some code because there's not information to help you right now.

Have you added this to your class?

  extend Forwardable

Posted in Login with Facebook Discussion

I try to never use OAuth to login unless it's something that'll need access to that account (like a deployment tool that needs access to Github, might as well login to the app with Github then). It makes perfect sense in this case.

The thing I don't like is using social login on a website, you can't use the app anymore if you stopped using the social site. That's crappy and with lastpass, etc it's real easy to just generate passwords and login with email anymore. And phones are getting better about this too, but they still lag behind a bit.

Mailchimp has a great post on social logins that has since been taken down it seems: https://web.archive.org/web/20180820002438/https://blog.mailchimp.com/social-login-buttons-arent-worth-it/

They're supposed to start using Chromium in the future, so we might have browser compatibility after all in the future! how weird will that be??

Hey Bigyan,

Check out this article on Heroku with the Rails asset pipeline: https://devcenter.heroku.com/articles/rails-4-asset-pipeline

The assets are designed to compile on the fly in development, but for production they get compiled and minified during deploy. Heroku also needs your Rails app to serve static assets, which is not the default for production. Normally, NGINX would do this but Heroku works a bit differently.

Oh neat, so you can have a button_to that submits a specific form?

I had always used it to have it submit a POST to a URL instead. Today I learned. 👍🧐

Posted in Upgrade to Mojave on Mac OS

Yeah, I do use Capybara. I tend to stick with the Rails official testing tools, and their system tests are run with Capybara. https://guides.rubyonrails.org/testing.html#system-testing

Posted in Upgrade to Mojave on Mac OS

It looks like there's a solution for that now at least: https://stackoverflow.com/a/53642942/277994

Let me know if that works for ya!

Posted in Upgrade to Mojave on Mac OS

Hey Pam!

I think a few things will break, but you should be fine. I don't have an upgrade guide specifically, but the steps are about the same:

  1. Upgrade your OS
  2. Upgrade & Install the latest XCode: xcode-select --install 2.5. You may also need to install XCode's Command Line Tools
  3. Upgrade your Homebrew install
  4. If you get an ld: library not found for -lstdc++ error installing gems, you can run: sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

I think that should be it.

Posted in Where do this code go? (Refactoring Rails Workers)

Ah yes, sorry! :)

I would pull the logic out into its own class. You can either make it a base class for the job, or you can make it a dedicated class.

This example is the inheritance approach:

class BaseWorker
  def do_this_action(website)
    ...
  end
end

class WebsiteWorker < BaseWorker

  def perform(website)
    do_this_action(website)
  end
end

Or if you wanted a dedicated class:

class DoThisProcessor
  def perform(website)
  end
end

class WebsiteWorker
  def perform(website)
    DoThisProcessor.new.perform(website)
  end
end

They're both very simple so you won't have too many tradeoffs either way you go in this case.

Posted in Where do this code go? (Refactoring Rails Workers)

Is it running the job twice? There's nothing here that would duplicate the calling of do_this_action that I can see.

Posted in Improve on these ActiveRecord requests?

Yeah, just adding a column like visits_last_30_days:integer and having it update every hour or night. You'd just query the impressions, sum up the total and save it to that column each time.

If you had a few common options you could cache multiple values so those common ones were super fast. Then fallback to doing the JOIN query for custom ranges which will be a little slower.

You should be able to query the Product table and join the impressions and use that for sorting. Here's an example of doing that: https://stackoverflow.com/questions/22234983/rails-activerecord-sort-by-count-of-join-table-associations

Skipping the cache will help you keep things simpler, since you'll always need the fallback join query.

Posted in Improve on these ActiveRecord requests?

You might try adding your own caches to the Product table. You could have a nightly or hourly cron update the cache so it isn't constantly being changed, but still getting regular updates.