Chris Oliver

Joined

292,390 Experience
93 Lessons Completed
295 Questions Solved

Activity

Posted in AASM state based on variable

This is more just a stylistic refactor, but you could also smash the event blocks inline to make them shorter. I also prefer case statements to ifs in situations like this. They're a little cleaner to read and using a ternary if statement for total_price also looks a little nicer, but this is all personal preference.

before_save :check_budget

event :over_budget { transitions from: [:new, :new_approval_needed], to: :new_approval_needed }
event :on_budget { transitions from: [:new, :new_approval_needed], to: :new }

def check_budget
  case aasm_state
  when 'new', 'new_approval_needed'
    (total_price > 500) ? over_budget : on_budget
  end
end

I didn't know about human_state! That's super useful! It also makes sense that they have locale options for the names. That's something I would have not even though of providing but makes perfect sense that they provide that.

Posted in Making a gem like thoughtbot's refills gem

Hey Josh,

I would love to see this! I think what you're looking for is learning how to create generators that install things from a gem. I've been building the simple_calendar gem and made an episode on how you can create generators that should be helpful. https://gorails.com/episodes/vlog-day-13?autoplay=1

The next step after you get a basic generator done is to take a look at the refills gem and see how they build the "import" generator. I'm not entirely sure, but it should be a good basis on how to do that. I've yet to dive into any of the USDS styleguides, but this would be a really really cool gem to make and should help adoption of it a lot. You'd be famous if you get this built. :)

Posted in Setup Ubuntu 14.10 Utopic Unicorn Discussion

Whoo! Thank you thank you! :)

Posted in AASM state based on variable

This is basically what the code would look like. There's not a significant way to refactor this other than pulling it out into a concern, but that hides the problem more than it cleans it up.

When you need to print out aasm_state, you can convert it from the string by doing this aasm_state.gsub("_", " ") to remove the underscores. You can then upcase the string or whatever you need to make it display nicer.

Absolutely! You can just pass in an array with all the meetings and then inside the block you can print them out differently using a helper or something. Rough outline here, first section goes in the controller.

# Pass @meetings into the calendar
@meetings = work_meetings + personal_meetings


<% month_calendar meetings: @meetings do |day, meetings| %>
<% meetings.each do |meeting| %>
<% if meeting.meeting_type == "work_meeting" %>
Code for work meeting
<% else %>
Code for personal meeting
<% end %>
<% end %>
<% end %>

Yeah, we could cheat and embed the stream. ;) But wouldn't it be sweet to build streaming video ourselves too? :)

That would be killer! This would be better for the chat portion of twitch, but the actual video streaming wouldn't be done using websockets.

Posted in twilio as verification mobile systems

Hey Corrado,

This is very related to things I have been planning to do soon. I was thinking about doing one-time email login links and verifying phone numbers is great. What part of this tutorial didn't work for you? I'd love to do this one soon.

Posted in Exporting Records To CSV Discussion

For that, basically all you need to do is shovel onto the CSV at the end after you loop through the invoices.

You can just say csv << ["custom", "footer"]

Posted in Sending emails with Mandrill Discussion

Unfortunately you'll have to paste all the bootstrap styles inline into the email templates. Emails only work with limited CSS.

Posted in Deploy Ubuntu 14.04 Trusty Tahr Discussion

Ah yep! That would do it! I was going to say, sounds like you've got a reference to "default" in your yaml file.

Posted in Deploy Ubuntu 14.04 Trusty Tahr Discussion

Yep! The real reason is so that you don't store your production secrets in git for security.

You can definitely do all that, but yeah...it might be a lot for your first venture into JS land! :) You can absolutely add the form in the same page and use the example I linked to for updating the calendar after you create a new event though. Shouldn't be too hard.

Posted in How do I implement voting in Rails?

Hey Karl!

This is a great question. Voting requires you to determine who did it (the voter, probably a User), what they voted on (the votable object), and which way they voted (up or down) which you could call like "direction" or you could simply store "1" or "-1" as an integer for easy calculating. 1 would represent an upvote and -1 would represent the downvote. You can basically create a model called Vote that keeps track of that information. There's a little more complexity to it when you need to sum up a user's karma based upon all the votes on their submissions, but that can be done by adding up all the votes on their submissions.

If you don't want to build all this from scratch, there's a great little gem called acts_as_votable that you can use: https://github.com/ryanto/acts_as_votable

It will help you create all the models and methods for voting and you basically just have to create links to actions to up and downvote submissions.

I did an episode on "liking posts" that works very similar to this. It's how I did the hearts on the GoRails episodes. https://gorails.com/episodes/liking-posts

It covers most of what you want, but they're basically all considered upvotes. You'd have to add the 1 or -1 code in there to handle downvoting and keep track of which. Then your submission's karma is just the sum of all the upvotes and all the downvotes.

Hope that helps you get started!

The easiest way is actually to use a JS response that sends back the calendar partial and you can just simply replace that part of the page. I made this a while back to show how that's done: https://github.com/excid3/s...

Let me know if that makes sense and accomplish what you're trying to do!

Posted in Refactoring Controller Methods Discussion

QUESTIONS is a list of all the questions to ask in the various states of the application. When you move to the next state, you can easily lookup the question from the QUESTIONS hash that you need to send out. What happens is that when the user sends a response with their first name, the @reply model gets it's state attribute changed over to "last_nm" and then it knows to ask for the last name. Each time a response is saved, it updates the state to the next one. I made a couple episodes on state machines and the state machine that can help you wrap your head around this part:

https://gorails.com/episode...
https://gorails.com/episode...

Posted in Scheduling Posts Discussion

That's a great question Brian. I think that what I was experiencing was that the jQuery code I wrote never gets re-executed when the page changes via Turbolinks. Usually jquery-turbolinks fixes that by hijacking the page change event and that automatically fixes it. You might double check to make sure that jquery-turbolinks is being included in your application.js file properly. That's about the only thing that I can think of off the top of my head.

Sure! Send it my way!

Posted in Which native app technology to pair with Rails

I'm a huge fan of React and think it's been particularly well thought out. Facebook has spent an enormous amount of time engineering things and came up with a pretty novel approach. One of the clues (for me) that I should avoid Ember was how quickly they were rolling in features and ideas from everywhere else. React's server side rendering is wonderful but Ember chose not to address it for a long time until React came out. They just end up copying a lot of things and I'm afraid that's going to lead towards bloat more than a fantastic framework.

RubyMotion is also a great option. I don't know too much about it, but I believe that this is what Basecamp uses for their iOS mobile app. They have their custom JS framework that works with Turbolinks so I'm sure this made a lot of sense to them.

I think you're pretty solid either way you go. The React community is about a thousand times larger than Turbolinks + RubyMotion I feel like which means you might get a lot more support along the way. This is just a hugely biased opinion from me though, so take it with a grain of salt. ;)