William Kennedy

Joined

10,490 Experience
74 Lessons Completed
4 Questions Solved

Activity

Posted in Multiuser Live Video Chat in Rails Discussion

The last part reminded me of the Brady Bunch. https://youtu.be/B7P6vEgMr4g?t=1027

Cool video(s)

Nice video Chris.

I did something similar on a project a while ago but not with the elegant stimulus js solution.

Something that I am wondering about Websockets. In terms of edges cases or pitfalls that one could fall into pretty easily, what are some good ones to look out for?

Posted in Issue deploying Rails app with capistrano

There are a few possible things going on here. Is your rails master key saved as an env varaiable?

ENV['RAILS_MASTER_KEY']

This is why the nil class error could be happening.

If you don't have the master key set then the following line won't work:

Rails.application.credentials.mysql[:username]

Try seeing if the master key ENV variable is set and just come back with any questions.

Posted in embed youtube in actiontext?

Hi ya na,

He did a whole talk about this.

https://railsconf.com/2020/video/chris-oliver-advanced-actiontext-attaching-any-model-in-rich-text

You can embed iframes into ActionText but you have to whitelist the iframe element.

##application.rb

config.to_prepare do
  ActionText::ContentHelper.allowed_tags << "iframe"
end

Posted in How to Test Validations in Rails Discussion

For validations, I sometimes like to use the shoulda-matchers gem

It's pretty cool because alot of use cases are set up already so it saves having to come up with the edge cases.

For example, in a model test (assuming Rails default not RSpec)
should validate_presence_of(:attribute)

For Rspec, you would write

it { should validate_presence_of(:attrinute) }

Obviously, it doesn't apply in some cases such as custom validate method but it's always a good start into a large codebase that might not have a massive test coverage.

I'm haven't watched the video and never used PurgeCss but I assume you would need to add matcher for .haml files.

/ postcss.config.js

let environment = {
  plugins: [
    require('tailwindcss'),
    require('autoprefixer'),
    require('postcss-import'),
    require('postcss-flexbugs-fixes'),
    require('postcss-preset-env')({
      autoprefixer: {
        flexbox: 'no-2009'
      },
      stage: 3
    }),
  ]
}

// Only run PurgeCSS in production (you can also add staging here)
if (process.env.RAILS_ENV === "production") {
  environment.plugins.push(
    require('@fullhuman/postcss-purgecss')({
      content: [

            // Matcher for haml
        './app/**/*.html.haml'

      ],
      defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || []
    })
  )
}

module.exports = environment

Posted in Stripe payments course getting out of date

Brilliant. I just happen to working on a project that needs to integrate payments. Looking forward to this.

For people that are asking about embedded signing,  I actually did this recently on a project. Basically, Docusign have an endpoint which returns the url for embedded signing. With the url, you simply redirect the customer off site to sign and then docusign will redirect them back to your app with a status. 


Create JSON like so 

signing_url_json = {
    userName: "something"
    email: email,
    recipientId: "1",
    clientUserId: 1,
    authenticationMethod: "email",
    returnUrl: url
}


Then post that JSON to the endpoint


"/envelopes/#{envelopeId}/views/recipient", signing_url_json.to_json


I can go into much more detail if people want me to. 

Posted in How do I transfer user data on delete

That's a good idea. Having a step-by-step process for deletion. Then you can just capture the new user who going to get everything transferred to. Best of luck. Hope I was able to help a little

Posted in How do I transfer user data on delete

Interesting. I think you could use callback for delete

class User < ActiveRecord::Base
  before_destroy :assign_courses

  private

  def assign_courses
    new_user = User.new_user_responible #some way of finding the next user responsible
    courses.update_all(user: new_user)
  end
end

Then you would just create a method for each table you want to transfer. 

assign_questions

You will also need to implement some scope on your User model to find the employee who is going to be assigned all the notes. 

Posted in How do I transfer user data on delete

You may have to divide and conquer the steps first. 

1. Identify the users you want to delete
2. Identify the employee
3. Transfer id
4. then delete user

depending on the table, you could use SQL to a large update provided you're able to find the users


UPDATE employees
LEFT OUTER JOIN user
    ON "{your condition}"
SET  employee.foreign_key = user.foreign_key
WHERE {condition}

I know it's not an exact answer but might point you in the right diraction


Posted in Can anyone suggest me best Ruby on Rails 5 book?

Rails Tutorial by Hartl is one that springs to mind. I also recommend Agile Development with Rails by Sam Ruby and Dave Thomas and DHH. After you build a few things, you will quickly get the hang of it

Posted in How do I generate dynamic classes?

Ya I was looking at that but then I found this cool library that accomplished what I wanted. 

https://github.com/digitaledgeit/sass-spacing

I'm play around with it some more and see if I can come up with a robust solution. 

Posted in How do I generate dynamic classes?

Is there a way to generate dynamic classes with scss/sass? For example, in my HTML. I want to write 

div class='mt-10'></div>
div class='mt-7'></div>
div class='mt-3'></div>

This should create a div that has a margin-top of 10px, 7px, 3px and I imagine the CSS will look like this:

.mt-{x} {
  margin-top: x;
}

Any help appreciated?



Posted in Writing Tests for Rack Middleware Discussion

Great video Chris. 

Posted in Open Closed Principle Discussion

Quick question Chris, when you were building out functionality like this for Hatch, how much of this structure do you plan versus how much did you arrive at through refactoring and iteration? 
Hi Arjun,

You could use normal JS with the setInterval method. Something like this: 

function timer(seconds){
    clearInterval(countdown);
    displayRemainingTime(seconds);
    const then = Date.now() + seconds * 1000;
    countdown = setInterval(() => {
        const secondsLeft = Math.round((then - Date.now()) / 1000);
        if(secondsLeft < 0) {
            clearInterval(countdown);
            return;
        }
        displayRemainingTime(secondsLeft);
    }, 1000)
}

function displayTimeLeft(){
 //update dom
}


I did something like this as part of a Javascript 30 course by Wes Bos. Recommend checking it out

William

Here is how I achieved the same effect using bootstrap 3. There is a div for each icon essentially. For font-awesome, you would just need to use the i class in the div. Hope that helps. 

<div class="input-group">
<div class="input-group-addon">€</div>
<%= f.text_field :field, class: 'form-control' %>
<div class="input-group-addon">.00</div>
</div>

Posted in Data Structure - Going back to the basic with Ruby

Hi Kelvin,

Let me try and put my own perspective

1 - Solid understanding of programming and computer science fundamentals. What do they want me to know?
Cracking the coding interview book
2 - Data Structure (list, stack, array, tree). 
Cracking the coding interview book
3 - With the data structure, how to search and sort with them. Best ways of searching and sort.
Cracking the coding interview book
4 - Understand the Big Oh problem and how to identify and solve it.
Cracking the coding interview book

Another topic that companies are asking for Senior Position (one day in the future)

5 - API design technique. What would it be?
Depends what the API does but I have built a few in the past and I wish I approached things differently. Here's a book I've been meaning to read http://apionrails.icalialabs.com/

6 - Strong familiarity with principles of database design and architecture. 

Refactoring Ruby, Code Complete etc...

7 -  Familiarity with OWASP and/or other web security practices.

Not sure but Handbrake is a useful gem for spotting security problems. That's I learned about security. 

8 - Knowledge of optimization tactics such as query optimization and caching

Rails Performance is a great course that covers Rails Performance in-depth https://www.railsspeed.com/ and Chris has a few videos on here as well. 

Hope that helps,
William

Posted in 'bcrypt' gem install Error

Your welcome but I think it was you who did all the work. Glad it's working. 
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.