Arjun Rajkumar

Joined

3,430 Experience
13 Lessons Completed
2 Questions Solved

Activity

Posted in Realtime browser updates with Cable Ready Discussion

had to change my cable.yml file to the below and its working fine.

development:
  adapter: redis
  url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>

test:
  adapter: async

production:
  adapter: redis
  url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>

Posted in Realtime browser updates with Cable Ready Discussion

facing a similar issue.. its broadcasting the data, but not updating the views. wondering if I'm doing something wrong related to action cable. were you able to fix yours?

hey, I have an image model. image belongs to product, and product has many images. this is how I did it.

<div data-controller="drags" data-drags-url="/products/:product_id/images/:id/move">

and in the stimulus controller, I replaced the url by this

let id = event.item.dataset.id
    let product_id = event.item.dataset.productId

    let data = new FormData()
    data.append("position", event.newIndex + 1)

    let url = this.data.get("url")
    let mapUrl = { product_id: product_id, id: id}

    url = url.replace(/product_id|id/gi, function(matched){
      return mapUrl[matched];
    })

    Rails.ajax({
      url: url,
      type: 'PATCH',
      data: data
    })

Posted in Caching with Etags Discussion

Does it make sense using this for an index page if it has pagination?

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..

THank you!

Arjun

Posted in How do I add minified JS files to the Rails Webpacker

I made a stupid mistake!

Can call minified JS files also with the same way.
So, instead of '<%= javascript_pack_tag 'something.min' %>' like I did before - I just have to use '<%= javascript_pack_tag 'something' %>' - and it runs.

Posted in How do I add minified JS files to the Rails Webpacker

ALso - I have added 'something.min' to the javascript/packs/something.min.js

Posted in How do I add minified JS files to the Rails Webpacker

I am trying to add min.js files - and getting an error.

This works while adding a normal .js file:

- app/javascript/packs/calendar.js
alert('Calendar loaded')

-# app/views/calendars/index.html.erb
Calendar
<%= javascript_pack_tag 'calendar' %>

The above code works. But when I try to add a min.js file it gives an error.
-# app/views/calendars/index.html.erb
Calendar
<%= javascript_pack_tag 'calendar' %>
<%= javascript_pack_tag 'something.min' %>

Can anyone share what the process is for adding min.js files to view via Rails Webpacker?

Thanks

Arjun

Posted in How do I embed a Rails app into another website?

Hey!

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:

  1. Sign up and get access to your dashboard.
  2. Add your store locations.
  3. 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.

Thanks,

Arjun

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

Thank you!! Solved.

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

Have update the code in event_worker.rb

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

Sorry.. Didnt explain this properly.

Both these different jobs website_worker and 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.

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

Hey!

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

The do_this_action code is repeated twice in two different workers.
The 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.

Posted in Anyone here built an iOS app with ROR backends.

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?

Posted in Anyone here built an iOS app with ROR backends.

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.

Thanks!

Arjun

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.
E.g.
user1.myapp.com
user2.myapp.com
user3.myapp.com
etc.
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!

Thanks

Arjun

Posted in Direct Uploads with ActiveStorage Discussion

IS this an alternative to using carrierwave etc? And the benefits are that this is faster? Can someone confirm this. Thanks!
Nice! Really useful. Was using the same db from heroku and hitting the row limits .. So migrating the db solves this. 

Would love to see more of these - Best practices for background jobs, elastic search implementations etc. Thank you!!
Hey! Would need to see more code before being sure if this is correct - but the error maybe happening because @account is not being set. Can you do a binding.pry and check the if @account is set propery.