Prasanna N

Joined

1,820 Experience
17 Lessons Completed
0 Questions Solved

Activity

This is so cool. You make it look so easy, and maybe it is. I should try committing to rails too.

Posted in Dynamic Nested Forms with Stimulus JS Discussion

you can find it here: https://github.com/excid3/jumpstart. See readme for instructions.

But frankly, I don't like using this template. In more than a few tutorials that this template is used, I encounted bugs that only slowed down the progress of following through the tutorial, instead of helping it.

Because the jumpstart script is constantly updated, older tutorials using it see a breakage.

Posted in Dynamic Nested Forms with Stimulus JS Discussion

Great episode Chris! Totally bypassed an entire gem.

Posted in Stimulus JS Twitter UI: Part 2 Discussion

Another great episode.
Stimulus isn't at the level of react/vue that provide great abstraction (no direct dom manipulation, html changes magically with state change etc).
It feels just like writing jquery.

BUT, the killer feature, over jquery, is the "sprinkled html".
Now, just by reading html we can get a hang of what's happening. Inability to do this always bugged when trying to reverse engineer a js behaviour in a website.

And here's a tad-bit refactored tweetform controller with constants, getters/setters:

import { Controller } from "stimulus"

class TweetFormController extends Controller {
  static targets = [ "body", "characterCount" ]

  initialize() {
    this.update()
  }

  update() {
    this.characterCount = this.bodyLength
    if (this.notATweet()) {
      this.characterCountTarget.classList.add('text-danger')
    } else {
      this.characterCountTarget.classList.remove('text-danger')
    }
  }

  submit(event) {
    if (this.notATweet()) {
      console.log('yup not a tweet')
      event.preventDefault()
    }
  }

  notATweet() {
    return (this.body.length > TweetFormController.maxTweetLength)
  }

  get body() {
    return this.bodyTarget.value
  }

  get bodyLength() {
    return this.body.length
  }

  set characterCount(value) {
    this.characterCountTarget.textContent = value
  }
}

TweetFormController.maxTweetLength = 10

export default TweetFormController

Posted in Stimulus JS Twitter UI: Part 1 Discussion

Great video Chris.

From Stimulus' docs, I found that we can refactor the controller class using javascript getter and setter methods, like so:

import { Controller } from "stimulus"

export default class extends Controller {
  static targets = [ "body", "characterCount" ]

  initialize() {
    this.characterCount = this.body.length
  }

  update() {
    console.log(`updating...${this.body.length}`)
    this.characterCount = this.body.length
  }

  get body() {
    return this.bodyTarget.value
  }

  set characterCount(value) {
    this.characterCountTarget.textContent = value
  }
}

Posted in How do I access google apis from a cron job?

My requirement:
My cron job (a ruby script) would sync specific contacts between 2 google accounts.

Eg: Account A creates a contact in his (android) phone as "Lead John". It gets saved in google contacts automatically the next time he connects to wifi.
Account B, later creates another contact in his phone as "Lead Doe". It too gets saved.

The cron job's purpose is to fetch and sync all contacts starting with "Lead" between the 2 accounts.
So, after the next run of the cron job, both Account A and B will have "Lead John" and "Lead Doe" in their phones even though each created only one by themselves.

When I set about to write the code for this, in the google developer console, while trying to get credentials for the "project" that I was creating, google asked from where I'll be accessing these apis. I chose "cron job/daemon" and selected "User data".
But then I got this alert: "User data cannot be accessed from a platform without a UI because it requires user interaction for sign-in".

Account A and Account B are just my friends and assume that I can get any sort of api keys/secrets from their account with their consent.

So, my question is, without resorting to developing a webapp with oauth enabled, can I get this cron ruby script working?

Loved this series!

Posted in API Authentication with an OAuth Provider Discussion

Same error. Chris, could you help?

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.