I have a page which displays all the products in a shop.
Each time a new product is added - two things happen.
1) The user is taken to the products/index page which shows a list of all the products added - including the new product.
2) A Sidekiq BG job starts. It basically goes to amazon and finds the price of the product added.
As the user is taken the products/index page after they add the product - they see that the new product is added (but the price and other info is empty). I want to somehow update this products/index page dynamically with the details of the new product (which is got via the Sidekiq worker).
I am just thinking how to approach this:
- Should I somehow get the worker to access this page and update the details?
- Should I do some polling method on the index page and just refresh it every few minutes.
- Or should I explore Action Cable to do this.
Any help will be appreciated. Just not sure which is the recommended way to do this..
I made a stupid mistake!
Can call minified JS files also with the same way.
I am trying to add min.js files - and getting an error.
This works while adding a normal .js file:
The above code works. But when I try to add a min.js file it gives an error.
Can anyone share what the process is for adding min.js files to view via Rails Webpacker?
I'm stuck with this - and would love some help.
Going to use an example to explain this. Storemapper (https://www.storemapper.com/) was build on Rails. It basically lets you add a store locator on your website.
It works in the following way:
- Sign up and get access to your dashboard.
- Add your store locations.
- And, copy and paste your embed code into your website
I am familiar with Rails but i'm stuck on embedding the code into another website.
Could anyone share how to get this done - and if you can link to any resources etc it will be really helpful. Just looking to learn and didn't find any tutorials on how to do this on the Rails app.
Thank you!! Solved.
Have update the code in event_worker.rb
Sorry.. Didnt explain this properly.
Both these different jobs
event_worker are run at different times. But in these two differrent jobs, the same function
do_this_action is being called. The
do_this_action does the same thing while being called via both these different workers.
So I was wondering if I can move the code in
do_this_action to some place and then include/require it in the two different workers - so that the code is not repeated.
I have two different workers
#app/workers/website_worker.rb class WebsiteWorker def perform(website) do_this_action(website) end def do_this_action(website) ... end end
#app/workers/event_worker.rb class EventWorker def perform(event) event.update(alive: true) website = Website.find_by url: event.url do_this_action(website) end def do_this_action(website) ... end end
do_this_action code is repeated twice in two different workers.
do_this_action uses Nokigiri to crawl a website, and then updates database accordingly.
Wondering what are the best practices to refactor this code?
Thanks Chris. Will chech this out.
Not really familiar with Reacht native at all.. So maybe a dumb question, but do you prefer building an iOS app with React Native or with the help of Turbolinks?
Hey all! Just looking to learn more about how to build iOS apps with ROR backend, and wondering if anyone has done the same? If you can share links/resources that has helped you build iOS apps, it'll be a great help.
Solved. Got help from Chris via email.
If anyone is stuck on this --
A CNAME just tells your browser which server to talk to. You'll have to write the code in Rails to check the domain to see if it's yours or a customer's in addition to checking the subdomain. You'll want to check the domain first, if it's a customers' look up their account. If it's yours, look at the subdomain, then lookup the account.
I run my app on Hatchbox, and have successfully created subdomains for each user.
How do I point user 2's own website (two.com) to user2.myapp.com?
This is what I did:
1) On Godaddy DNS settings under two.com account, I added a CNAME with name 'community' and value 'user2.myapp.com'
So I thought when I visit 'community.two.com' it should display 'user2.myapp.com'.
But, instead it is displaying myapp.com.
Is there something I should add to the NGINX file on Hatchbox - saying 'community.two.com' and 'user2.myapp.com' are connected.
I remember when I was using Heroku - I had to add the domains on Heroku also. Just wondering how to fix this.
Any advice will be really helpful!
Would love to see more of these - Best practices for background jobs, elastic search implementations etc. Thank you!!
Wondering how to do this on the front-end.
Should I just use jquery? Or something else?
Very useful feature this is. Thanks for sharing. Also discovered 'any?' in this episode - I;ve always been using present? to check - but Googled this and it says .any? is faster. So learnt about that too :) Thanks!