Chris Oliver

Joined

292,890 Experience
93 Lessons Completed
295 Questions Solved

Activity

Hey Wesley,

Is the line.text for those actually a string of question marks? I was going to suggest that you could put an if statement in there to check, and then you could have your default "No date" or whatever when it detects that.

Does that help any?

Posted in data consistency for invitation registration

You probably are in a situation where it doesn't matter either way you go. You can just use the ProductUser model and add a role to it if you want to add owners in there. That'll work really nicely. You can then just have:

class User
  has_many :product_users
  has_many :products, through: :product_users
  has_mnay :owned_products, ->{ where(product_users: {role: :owner}) }, through: :product_users, class_name: "Product"
end

This should allow you to have a single table for everything, you won't need the user_id on Product, and the only other thing with this is that when you create a Product you must make sure to create the ProductUser record and set the role to owner.

That's absolutely on my list. I need to have someone help me with that part as making the videos on their own is time consuming enough. Expect to have transcripts with code snippets sometime in the near future if everything goes well. :)

This looks pretty cool. It might need some updates for newer versions of Rails since it hasn't been updated in a while, but you might check to see if anyone has been maintaining a fork.

Posted in Rails console hacks :)

Hey Sascha, I'd write it like this:

Order.all.each do |tname| 
  tname.update_attributes(team: User.where(:id => tname.user_id).pluck(:team).shift)
end

The problem is when you use self it doesn't point to the tname object, causing that issue.

Posted in The Params Hash | GoRails

Really good question and one I am going to cover in more depth in some future episodes. Basically blog_path is a Ruby method that returns a URL from your routes file. The path it returns looks like "/blog". The reason you need that is that when you submit a form, you need to pass it a URL that accepts the form data so it can save it to the database. Usually that's a specific url dedicated to just saving data. For example, if you open up the HTML on the login form on GoRails, you'll see that it points to /users/sign_in as the action which knows how to take your username and password, validate it, and sign you in:

<form class="new_user" id="new_user" action="/users/sign_in" accept-charset="UTF-8" method="post">

Posted in Integrating Braintree (and PayPal) - GoRails

I imagine you're wanting to build something like that into your own app rather than using PayPal's? You'd probably need to custom build that if you want your app to have that sort of functionality. You could integrate with Sendgrid or something for inbound email that is addressed to your app to handle it.

Yeah, you can have a comment as a commentable, allowing you to have Comments with comments if you like. That's how you would normally setup threaded comments. You might want to put some limits on the nesting so you don't get threads that are too far nested in. Facebook limits it to one layer for example.

Heck yes. Let's Encrypt seems awesome, but then when I started poking around it was like okay well this seems a little more complicated than I originally thought.

I'll try setting this up for my personal blog and try to make a tutorial on it.

Posted in data consistency for invitation registration

What I would recommend is that you create a join table for ProductUsers. This will be everyone who has access to the account. You'll duplicate the owner in this list so it's easier to query. You can keep the user_id on the product so that you know who is the owner of it.

When you create that form, you can use like devise_invitable in order to loop through those users and invite them. It creates User records in the database that are saved without passwords. Then it emails out links to set your password to everyone. Since it stores them in the database, you can use those IDs from those records to create the ProductUser join table between those users who don't have accounts yet and the product. As soon as they set their password, they'll automatically have access to the Product.

If you're not using Devise, you can use the same approach and build your own invitation system rather than using that gem plugin.

Make sense?

It definitely does balloon in complexity which is why this is a tradeoff that often isn't valuable until your servers are falling down because you have too much traffic. It's a serious investment coding wise and requires a lot of engineering time to improve performance.

I'm not familiar with the Gon gem, but I would say that if you've got a resource like a BlogPost, you could take your CanCanCan or Pundit scopes and then just simply ask for all the things your view needs (show, edit, update, destroy, whatever you need) and convert that to a JSON object that you can pass to your JS. This way you've got a simple JSON object with a bunch of booleans that can be easily evaluated client side without having to do much logic duplicated on both the client and server.

Sounds like it turned out really smoothly! :D

You could do just one controller and then just make sure to pass in the type into the URL or the form as a hidden field. Then you could use that logic to create an Asset or a Component.

Ha! I'll take it. :)

Yeah. It's helpful to so that you can save the correct type easily, although you don't have to.

I'm not sure I totally understand, but you might consider creating a Component class that inherits from Asset so that you can store all those in the assets table but treat them differently. This is generally called single table inheritance.

http://api.rubyonrails.org/classes/ActiveRecord/Inheritance.html

I think that's what you are looking for?

Posted in Testing your markdown

Also, I posted this in slack, but for anyone else that sees this, I forgot that I'm using Redcarpet instead of html-pipeline anymore. It's because html-pipeline is a real pain to deploy to Heroku (or at least was).

Posted in Testing your markdown

Tables aren't actually part of the official Markdown spec, so you'll see that they don't work all the time. That said, the Github-markdown gem supports it as long as you're rendering as github formatted markdown. I believe mine is but I haven't tested it.

Are you running gfm: true as well?

Posted in Deploy Ubuntu 16.04 Xenial Xerus Discussion

Unfortunately they haven't released a package for xenial yet. It's on their todo list, but they said by June at the latest. That's a long time from now.

Here's how you can install it manually: https://www.phusionpassenge...

Oh, I see what you mean. You could do that just as well, no particular reason either way.