Friday, October 25, 2013

My Bundler Feature was Merged

My PR to Bundler  was merged!
This fixes the issue: Warn if the same gem (same version) is added twice. bundler/bundler-features#22

Try it out: Open a Gemfile in on of your projects and duplicate one of your gems.
do a bundle install
You should get a warning telling you that you have a duplicated gem and what it is.
This is the warning you'll see:

"Your Gemfile lists the gem #{current.name} (#{current.requirement}) more than once. You should probably keep only one of them. While it's not a problem now, it could cause errors if you change the version of just one of them later."
Yay!!

Wednesday, October 23, 2013

New Relic Rocks

So I am here in San Francisco for the Future Stack Conference because New Relic gave Rails Girls a scholarship. Someone else was supposed to come but she couldn't make it and I was next on the list. So New Relic paid for me to fly here, sent a car for me; a fancy, shiny, black car which dropped me off for a 3 night stay at the Grand Hyatt Hotel in Union Sq. My room is amazing. Then I got an amazing goody bag with a cool Future Stack tote, t-shirt, stickers, other swag and a generous food stipend. Wow. I won the scholarship lottery.

I walked around Union Sq. for hours today shopping for the perfect scarf. The first one I found is the one I ended up buying many hours later. I got a nice lunch and dinner. Now am in my pajamas relaxing and getting ready for the long day and night tomorrow.

Tuesday, October 22, 2013

Github Pages

http://jendiamond.github.io/

Wow, I can't believe that it is finally up! I had an incredible burst of focused energy and in my own house and at my desk even.

I was having a hard time getting the blog to publish and after a while I realized that the layout was not correct. I fixed that and it posted. Then I continued onward to styling and adding pages. I was so happy and proud of myself when it finally worked. There are so few of these moments amidst the struggle that I make sure I acknowledge them.

I am leaving for the Future Stack conference tomorrow morning so I am going to hit the hay.

Hooray!!! Hooray!!! Hooray!!!

Thursday, October 17, 2013

Model View Controller Explanation

Model The classes which are used to store and manipulate state, typically in a database of some kind.

View The user interface bits (in this case, HTML) necessary to render the model to the user.

Controller The brains of the application. The controller decides what the user's input was, how the model needs to change as a result of that input, and which resulting view should be used.


Let's use some of this to make a simple little text editor:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
filename = ARGV.first
script = $0

puts "We're going to erase #{filename}."
puts "If you don't want that, hit CTRL-C (^C)."
puts "If you do want that, hit RETURN."

print "? "
STDIN.gets

puts "Opening the file..."
target = File.open(filename, 'w')

puts "Truncating the file.  Goodbye!"
target.truncate(target.size)

puts "Now I'm going to ask you for three lines."

print "line 1: "; line1 = STDIN.gets.chomp()
print "line 2: "; line2 = STDIN.gets.chomp()
print "line 3: "; line3 = STDIN.gets.chomp()

puts "I'm going to write these to the file."

target.write(line1)
target.write("\n")
target.write(line2)
target.write("\n")
target.write(line3)
target.write("\n")

puts "And finally, we close it."
target.close()

Notes - Rails Tutorial Chapter 3.1

Sent PR to Bundler  hopefully it will get closed soon.
This fixes the issue: Warn if the same gem (same version) is added twice. bundler/bundler-features#22

To create the static views I am mainly in the app/controllers and the app/views directories

The config directory is where Rails collects files needed for the application configuration.

app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
end

New in Rails 4
  • Previous versions of Rails used PUT in place of PATCH, and Rails 4.0 still supports this usage, but PATCH matches the intended HTTP usage better and is preferred for new applications. So GET, POST, PUT, DELETE is now GET, POST, PATCH, DELETE.

    Idempotence  is the property of certain operations in mathematics and computer science, that can be applied multiple times without changing the result beyond the initial application. It literally means "(the quality of having) the same power", from idem + potence (same + power).



Wednesday, October 16, 2013

Notes - Rails Tutorial Chapter 3.1 - Static Pages

I set the sample_app on GitHub and Herouku.

underscore method

Rails' ActiveSupport adds underscore to the String methods using the following code (This is NOT a String method in Ruby)

class String
  def underscore
    self.gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
  end
end
underscore(camel_cased_word)
Makes an underscored, lowercase form from the expression in the string.

Changes ‘::’ to ‘/’ to convert namespaces to paths.

  'ActiveModel'. underscore    # => "active_model"
  'ActiveModel::Errors'.underscore    # => "active_model/errors"


As a rule of thumb you can think of it as the inverse of camelize, though there are cases where that does not hold:
'SSLError'
.underscore.camelize # => "SslError"

CREATE & DESTROY

$ rails generate controller FooBars baz quux
$ rails destroy controller FooBars baz quux
$ rails generate model Foo bar:string baz:integer
$ rails destroy model Foo
$ rake db:migrate
  We can undo a single migration step using
$ rake db:rollback
  To go all the way back to the beginning, we can use
$ rake db:migrate VERSION=0

Tuesday, October 15, 2013

has_many & belongs_to

The Microposts Resource parallel the User Resources.

config/routes.rb
DemoApp::Application.routes.draw do
  resources:microposts
  resources:users
  .
  .
  .
end

Active Record

Forming associations between different data models with has_many and belongs_to.

app/models/user.rb
class User < ActiveRecord::Base
  has_many :microposts
end
app/models/micropost.rb
class Micropost < ActiveRecord::Base
  belongs_to  :user
  validates, :content, length: { maximum: 140 }
end
micropost_user_association


Hierarchy


demo_controller_inheritance

Middleman Blog

I am working on setting up a new Middleman blog to replace the jekll one I set up and mangled. http://jendiamond.github.io/ I was having a problem with having multiple versions of Middleman installed so I deleted them and started over with the oldest version that I have installed for  working on the RGSOC Team blog and the Bundler website. I may install RVM finally so I can use the newest version. I need some assistance and guidance. Time to check in with Cynthia. She said she'd show me RVM.
http://rubylearning.com/blog/2010/12/20/how-do-i-keep-multiple-ruby-projects-separate/

Friday, October 11, 2013

Users Resource

Back in Griffith Park with Lars. It's a beautiful day, the kids are playing and the crows are making their hollow clicking noises that sound like woodpeckers.

I am working my way through Chapter 2

A break down of 2.2
  1. The browser issues a request for the /users URL.
    a. We start with a request issued from the browser
    i.e., the result of typing a URL in the address bar or clicking on a link.
  2. Rails routes /users to the index action in the Users controller.
    a. This request hits the Rails router which dispatches to the proper controller action based on the URL and the type of request. The code below creates the mapping of user URLs to controller actions for the Users resource. This code effectively sets up the table of URL/action pairs seen in Table 2.1

    config/routes.rb
    DemoApp::Application.routes.draw do
      resources :users
      .
      .
      .
    end
    
  3. The index action asks the User model to retrieve all users (User.all).
    a. This index action has the line @users = User.all

  4. app/controllers/users_controller.rb
    class UsersController < ApplicationController
    
      def index
        @users= User.all
      end
      .
      .
      .
    end
    
  5. The User model pulls all the users from the database.
    a.  @users = User.all  asks the User model to retrieve a list of all the users from the database
  6. The User model returns the list of users to the controller.
    a. Then it places all the users from the database in the variable @users

    app/models/user.rb
  7. class User < ActiveRecord::Base
    end
    
  8. The controller captures the users in the @users variable, which is passed to the index view.
    a. Once the @users variable is defined, the controller calls the view. Instance variables, variables that start with the @ sign, are automatically availablein the view; in this case, the index.html.erb view iterates through the @users list and outputs a line of HTML for each one.

    app/views/users/index.html.erb
  9. The view uses embedded Ruby to render the page as HTML.
    a. The view converts its contents to HTML

    app/views/users/index.html.erb (The view for the user index.) 
  10. <h1>Listing users</h1>
    
    <table>
      <tr>
        <th>Name</th>
        <th>Email</th>
        <th></th>
        <th></th>
        <th></th>
      </tr>
    
    <% @users.each do |user| %>
      <tr>
        <td><%= user.name%></td>
        <td><%=user.email %></td> 
            <td><%=link_to 'Show',user %></td>
            <td><%= link_to 'Edit',edit_user_path(user) %></td>
            <td><%= link_to 'Destroy',user, method  :delete,data:                    { confirm: 'Are you sure?' } %></td> </tr> 
    <% end %> </table> 
    <br /> 
    <%= link_to 'New User', new_user_path %>

  • The controller passes the HTML back to the browser.
    a. The HTML content is then returned by the controller to the browser for display

  • Leaving the park because a modeling shoot just moved in under the gazebo.

    REST Architecture (REpresentational State Transfer) REST is an architectural style for developing distributed, networked systems and software applications such as the World Wide Web and web applications. Although REST theory is rather abstract, in the context of Rails applications REST means that most application components (such as users and microposts) are modeled as that can be created, read, updated, and deleted—operations that correspond both to the HTTP request methods POST GET PATCH and DELETE.

    Thursday, October 10, 2013

    Scaffolding

    I was having a weird zombie day so I used my last sugar scrub at Spa Pura in Montrose. Once I was re-invigorated and totally clean I went to the Coffee Bean next door and started the first part of Chapter 2: 2.1 Planning the application,  2.1.1 Modeling demo users, 2.1.2 Modeling demo micro posts; basically scaffolding.

      No one was signed up for the study group so I stayed home this week. I am going to change the location back to Panera in Glendale.  It's nice that Syrup is downtown and it is open so late but it is kind of hard to concentrate there. It's even harder to concentrate at my house right now.

      Wednesday, October 9, 2013

      Heroku - Yak Shaving

      I haven't pushed to heroku in so long that all my apps were sleeping. I realized that there was not much in there that was useful so I set about with some yak shaving and deleted at least ten apps. I had to install heroku on my laptop. There is now a toolbelt.  My process of adding heroku:

          $ sudo -i     This sets me up as the root user.

          $ wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh  

      This didn't work so Lars did this:

          $ sh ./the-name-of-the-script  

      wget is a program that downloads files from web servers. You could run: $wget http://jendiamond.com/index.html and get the index.html from your site. In this case, you are using wget to download a script from heroku's server and then piping it to "sh" so you're downloading a script from the internet and running it locally as root. For whatever reason it didn't pipe to sh properly so I just ran:   
      $ sh ./the-name-of-the-script
      This worked and I ran $ heroku create Then $ heroku login to check it out. After freaking out that my heroku app url only said: "An error occurred in the application and your page could not be served. Please try again in a few moments." I finally read the part in the tutorial that says: "Unfortunately, the resulting page is an error; as of Rails 4.0, for technical reasons the default Rails page doesn’t work on Heroku." I renamed my heroku app to railstutorial-jendiamond.

      Lars and I are sitting under the gazebo in Griffith Park. We have a lot of layers on so we were pretty comfortable. We are sitting at a table with a woman named Lucia who is studying for her Masters in Psychology at USC. We saw 8 deer wandering around today. It's a lot quieter here in the rain. It's around 2:30 and it is starting to get pretty chilly so we are heading home. I am going to stop off at the Observatory so I can look at the view.

      Team Dysania and Team Bundler were going to meet up tonight to go over the Rails Girls materials so everyone felt comfortable coaching at the upcoming Rails Girls workshop. Jessica got sick and couldn't go so we cancelled until sometime in the future.



      Tuesday, October 8, 2013

      Rails Girls logo

      Happy Birthday Heather Hike (and congrats on getting engaged) with Heather, SoYoung Amy and I at 8am.  I only slept 4+ hours last night but I still managed to hike and now I am working finishing up Ch. 1 of the Rails tutorial at Trails Cafe in Griffith Park. I am getting distracted with everyones request for something different for the logo: the ocean, traffic, palm trees, the Hollywood sign, non-recognition of the buildings, dislike of the girl. I will address this later when I am rested. BTW - The Capital Records Building, The Chinese Mann Theater, The Watts Towers & Griffith Observatory.

      My table neighbors are playing gin rummy game while Curtis the dog with his curly blond hair and caged mouth sniffs around for dropped food. It's a beautiful day in the park.

      I finally got tired, went home and fell asleep until 6pm.  I worked on another design for Rails Girls LA because no one was sold on the first design. I like them both. I tried to add waves but nothing really worked. I don't really want to add traffic and I think it really needs some specific buildings. I made the Rails Girls logo act as the Hollywood sign, seems like a good compromise. If not someone else can take a turn. I just wanted to get something done before we met up on Wednesday.




      Monday, October 7, 2013

      Rails Tutorial Phase 2

      Rails Tutorial Phase 2

      Brand New Day

      I am re-starting Michael HartI's Rails Tutorial. I made it up to Chapter 10 the last time I did it but I never really felt like I was really fully understanding what I was actually doing.

      My plan this time is to go through it as quickly as I can and have some experts from whom I can ask related questions. I also want to try to do some small Rails sites on my own. 

      I was considering installing rbenv on my Linux machine but I realized that I already have Rails 4 installed and my Ruby version is 1.9.3 so there is still no need for it.

      Good advice for today:
      Don’t worry about what you need to know in order to finish a project, you already have everything you need to start.
      Hannah Howard sweetly let me study at her place today which really helped me focus. I met her partner Ben and all their 3 dogs and their parrot. The parrot is so funny. He really wanted some attention so he flipped upside down and flapped his wings frantically. He talks and talks screeching watchout!, thank you, no that's a no, hey no biting,  it's okay, watch out.

      I worked on the preliminary version of a Rails Girls LA logo last night until 3am. I was in the zone.