Chris Oliver

Joined

292,890 Experience
93 Lessons Completed
295 Questions Solved

Activity

Posted in Refactoring with the Null Object Pattern Discussion

A combination of decorators and the null object pattern can go together quite well. Curious to hear how it goes for you!

Posted in Refactoring with the Null Object Pattern Discussion

Awesome, glad you liked it! :) Definitely want to cover more of these design patterns and their practical uses.

That turned out really clean! I'm glad you guys got it working. Airpair is pretty great.

Posted in Refactoring with the Null Object Pattern Discussion

Yes, the none method is super helpful for situations like that. I'm really glad they added it.

Posted in Refactoring with the Null Object Pattern Discussion

Definitely. You can use this a bit too early and it just is more painful than anything. The example of the navigation is bad because right now, I'd rather have the if statement, but in the future as it gets way more complex, null objects would make more sense.

There's certainly a balance to find when applying this (like any pattern).

Posted in Setup MacOS 10.10 Yosemite Discussion

Awesome! Glad that worked. The error came from trying to install a gem into system ruby. Some people will tell you to use "sudo" to fix it, but that's not fixing the real problem which was that it was using the wrong version of Ruby.

Good rule of thumb is that you should *never* use "sudo" when working with Ruby. It's always a sign you're doing something outside of rbenv and something's configured wrong.

Fingers crossed the rest of your setup goes well!

Posted in Setup MacOS 10.10 Yosemite Discussion

It sounds like you aren't using the proper version of Ruby and it's trying to install in your system Ruby. Make sure you didn't miss any commands and try restarting your terminal. When you run "which ruby" you should get something like "/Users/chris/.rbenv/shims/ruby".

Posted in Deploy Ubuntu 14.04 Trusty Tahr Discussion

Most of my projects are private and I put them on Github (paying for private repos) and you could easily store them privately on Bitbucket. In either case, your Capistrano URL will securely authenticate with Github or Bitbucket using your SSH key to check out the code. It logs in using that so you don't need to use a password to clone the code on a deploy.

Posted in Deploy Ubuntu 14.04 Trusty Tahr Discussion

Always the file named Gemfile in the root of your Rails application. It's the defining list of dependencies for each Rails app. You save it in each app so that all of them can use different versions without fighting each other.

Posted in I'm lost and can't find the way out

Hey,

Forms normally send a POST request and since the user is saving data, you definitely want a POST.

You'll need two routes for this, one to show the form and one to save the data after the form is submitted. I would recommend changing your controller to Links plural so you can stay with the standard naming.

get 'links/minecraft' => "links#minecraft"
post "links" => "links#create"

Then you can make your controller:

class LinksController < ApplicationController
  def minecraft
    # This is empty so the view can render the form
  end

  def create
    if current_user.update(user_params)
      redirect_to action: :minecraft, notice: "Successfully saved your Minecraft ID"
    else
      redirect_to action: :minecraft, alert: "Please input a valid ID"
    end
  end

  private

    def user_params
      params.require(:user).permit(:minecraft_uuid)
    end
end

And your form would be a normal form_for current_user using the minecraft_uuid as the field to render out.

Since you've got some code to look up the Minecraft UUID, you can add that to the model as a validation to look up and verify it. Add an error to the record if it is invalid and that will cause the update call to return false.

Posted in Ruby Version Managers Discussion

I'd definitely just stick with one.

Posted in PDF Receipts Discussion

Ah yeah, you're right. I have always been careful about hashes when it comes to ordering because I wasn't sure it was a requirement for the ruby implementation.

Posted in PDF Receipts Discussion

Yep, you can call the "render" method like you normally would and send it as an attachment to email or upload it to S3

Posted in Liking Posts Discussion

You can do a SQL ORDER on the created_cat column by adding liked_posts.order(created_at: :desc) or :asc if you want ascending.

I've used At.js in the past and it has worked quite well. http://ichord.github.io/At.js/

Posted in Select Form Helper Required True Not Working

Ah yes, that's one of those odd gotchas because it accepts two hashes where as most of these methods accept only one. It's a tag with a whole lot of options, so it kind of makes sense, but seems a bit overly complicated.

Posted in Import CSV data using RubyZip and Postgresql COP

Wow so it was as simple as the missing newline character?!

Posted in Setup MacOS 10.9 Mavericks Discussion

Haha! Actually OSX comes with an older version of Ruby. We use that to install Homebrew so we can make installing a ruby version manager easily.

Posted in How to add records to has_many :through association

Hey Wesley,

So you said that this is a form for a new Site? A site has_many models, not many sites. Should your form be for association :sites instead?

Posted in Setup MacOS 10.10 Yosemite Discussion

Sounds like you didn't insTall Postgres yet. Doing that should fix yOur problem.