Activity
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:
- Upgrade your OS
- Upgrade & Install the latest XCode:
xcode-select --install2.5. You may also need to install XCode's Command Line Tools - Upgrade your Homebrew install
- 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.
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.
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.
I would recommend Rails's ActiveStorage. I've done some episodes on it which you can checkout, but it's the official Rails file uploading library and definitely the easiest.
You'll still need to have imagemagick installed. They all use this for the actual cropping and resizing of images.
Carrierwave works too, but it requires some other setup like creating Uploaders so you can define how a file gets processed.
ActiveStorage works a bit different where you define how the file gets resized when you use it in your view. Carrierwave does this as soon as the file is uploaded instead. Both have some advantages but ActiveStorage should definitely be easier.
You can pass subdomain: nil into your url helpers to change the subdomain. Something like link_to home_url(subdomain: nil)
Posted in Rails Application Templates Discussion
Hey Mark, I just fixed that. Just need to modify the navbar link to use "#" instead of root_path. https://github.com/excid3/jumpstart/commit/7a49c0fe5cbbd3621288cb00b9ca390099d869a9