Leave a comment

Learning Ruby (and why I should have learned it earlier)


Bob Roberts:

I learned Rails from a Rails expert that did not know Ruby very well :( I learned so much Ruby just from messing around in Rails console.

Originally posted on Erik Jenks:

The Internet has said it over and over. Did I listen? Not right away. The almighty Interwebs have said “LEARN RUBY FIRST!” Nah, I do things my way, I do what I want. I should have listened.

I spent the past week and a half sitting down, learning the basics of Ruby, and guess what. Rails makes SO MUCH MORE SENSE NOW! So I should have listened to the wise words of those who have come before me.

Actually, I think that attempting to learn Rails before Ruby helped some. I understood some of the concepts, but then after diving deep into Ruby it all started to click.

The use of hashes, arrays, classes, and all the verbiage that came with Ruby became a snowball in my mind. Once the ball began rolling I was able to comprehend even more. I went back through some of my projects that I…

View original 149 more words

Leave a comment

Railsbricks Setup


Bob Roberts:

Cool cool find. Kudos to Nico Schuele for creating this gem

Originally posted on Troy Leak:

Today I found out about railsbricks. It’s a ruby gem that does the complicated task of setting up trivial functionality for your site like user logins, database configuration, admin pages, and other things like that. Extremely helpful in that endeavor was this blog post, which helped me parse some of the options I was presented with.

I did run into one problem that was not covered in his post, however. It seems the team that makes Postgresql keep moving around their psql.conf file and that causes your application to flip out without some extra configuration. As this was a test application, I went with SQLite3 for my database for simplicity’s sake.

Overall, though, railsbricks is another extremely helpful tool in creating rails apps quickly and conveniently.

View original

Leave a comment

High Charts Interactive Grids


Bob Roberts:

We use High Charts as well. Excellent tool imho

Originally posted on Stephen Emo's Blog:

Now that my web site has been live for a couple of months I have had time to go back and see some improvements I can make. The first thing I noticed was regarding the Highchart graphs, I noticed that you could filter out the lines of the graph that you where not interested in by clicking on the related legend. So I updated the graph so that clicking on it does not move you to a new page which meant this useful dynamic legend filter functionality could be used. You can still move pages by clicking on the left hand side grid boxes

Interact with the High Charts Graphs Interact with the High Charts Graphs

The second thing I noticed was that smaller towns ended up with the highest price. This was due to the low volumes of sales in the area. This meant a single site valued at 600,000 pounds would give high average…

View original 24 more words

Leave a comment

Refactor: A clever way to DRY up your create action


Originally posted on Dear Programmer:

Anyone that has spent at least 5 minutes with Ruby on Rails will recognize the following code:

class PersonController

  ...

  def create
    if person.save
      flash[:success] = 'Person saved!'
      redirect_to person
    else
      flash[:error] = 'Person not saved.'
      render :new
    end
  end

  ...

end

It’s probably the single most common method in a rails controller and since it follows the same pattern in each controller, it’s ripe for DRYing up!

Here’s how:

In your application_controller.rb add the following method:

def save_and_redirect(new_object, success_msg, error_msg, redirect_path)
  if new_object.save
    flash[:success] = success_msg
     redirect_to redirect_path
  else
    flash[:error] = error_msg
    render :new
  end
end

Then in your controllers call the method like this:

def create
 save_and_redirect(person, 'Person added!', 'Person not added.', person)
 end

And that’s how it’s done.

Also, in case anyone was wondering where my @person = Person.new(params[:person]) went and why I don’t use instance variables; I use Decent Exposure. Check it out!

However, the above…

View original 47 more words

Leave a comment

Rails 4: Flash message persists for the next page view


Originally posted on Ruby on Rails Developer Community:

The flash variable is intended to be used before a redirect, and it persists on the resulting page for one request. This means that if we do not redirect, and instead simply render a page, the flash message will persist for two requests: it appears on the rendered page but is still waiting for a redirect (i.e., a second request), and thus the message will appear again if you click a link.

To avoid this weird behavior, when rendering rather than redirecting we use flash.now instead of flash.

The flash.now object is used for displaying flash messages on a rendered page. As per my assumption, if you ever find a random flash message where you do not expect it, you can resolve it by replacing flash with flash.now.

View original

Leave a comment

What Ruby On Rails is, and the only other three things you really need to understand to get started


Bob Roberts:

My favorite quote:
“The terminal is a piece of voodoo”
I totally felt that way the first time in a console!!

Originally posted on Ruby Warriors:

What is Ruby On Rails?

Ruby is a programming language. Hardcore code – the stuff that’s impossible to understand for an untrained person. You can do stuff with this language; anything, really. You can program stuff, write software with it etc.

Rails is bit like a piece of software you use to

View original 530 more words

Leave a comment

2014 in review


The WordPress.com stats helper monkeys prepared a 2014 annual report for this blog.

Here’s an excerpt:

The concert hall at the Sydney Opera House holds 2,700 people. This blog was viewed about 13,000 times in 2014. If it were a concert at Sydney Opera House, it would take about 5 sold-out performances for that many people to see it.

Click here to see the complete report.