Showing posts with label Git. Show all posts
Showing posts with label Git. Show all posts

Wednesday, January 25, 2012

Git and NetBeans 7.1 Problem: Everything in the project appears modified, but is not

Hi,

Recently I started developing a new Symfony2 project on Windows following the tutorial on http://tutorial.symblog.co.uk

I like to use Git in combination with BitBucket.org. I used Git integrated in NetBeans in combination with msysGit and recently found a very strange bug. Everything in NetBeans appeared as modified but actually wasn’t. Very strange I thought, and created an issue on NetBeans bugzilla, than I found out that it is a duplicate of the other issue http://netbeans.org/bugzilla/show_bug.cgi?id=198451.

It appeared to be a problem related to line endings in different operating systems. Though msysGit is capable of ignoring this differences, it seems to be that JGit, the tool on which integration with Git is made in NetBeans, doesn’t. So now what should we do to make it work is to add the line

[core] autocrlf = false

to project’s .git/config file. But that’s not enough, also we would need to follow the instructions in http://help.github.com/line-endings/.

So for Windows I needed to run this script in msysGit :

# Remove everything from the index
$ git rm --cached -r .

# Re-add all the deleted files to the index
# You should get lots of messages like: "warning: CRLF will be replaced by LF in <file>."
$ git diff --cached --name-only -z | xargs -0 git add -f

# Commit
$ git commit -m "Fix CRLF"

Hope this one will save you time and please vote it in NetBeans bugzilla to notify developers that we need it solved. 

2012-01-24_1436For any ideas, concerns, requests please leave a comment. Thank you.

Thursday, January 19, 2012

Git and first Symfony2 project in NetBeans

apple-touch-iconThis post is a part of series of posts dedicated to developping in Symfony2. If you missed the first part I highly recommend you to go and read that one before you continue with this post.

  1. Setting up Windows environment for Symfony2 developing with NetBeans, XAMPP and Git

Hello, today I’ll show you how to create your first Symfony2 project in NetBeans and how to push and pull it to/from Github.

Creating the fiRst SYMFONY2 project IN NETBEANS

Ok go File –> New Project –> PHP –> PHP Application. Click Next.

2012-01-19_1432

Create the project directly into your XAMPP server, htdocs folder. Click Next.

2012-01-19_1434

We should modify the starting URL because in Symfony2 the application starting point is /web/app_dev.php like that we can assure that when we are running the application it is correctly started. Also give it a descriptive name like “FirstApp”.

2012-01-19_1445 

On PHP Frameworks step select Symfony2 checkbox and click Finish. Now your application should be generated.

RUNNING APPLICATION

Now start your Apache and MySQL from XAMPP Control Panel. Go to NetBeans and click F6 (Run the application).

Hooray!!! Our first application is up and running. Now we need to configure our application, and doing this will change the app/config/parameters.ini

AccessSymfony2FirstApp

configure_1_stepconfigure_2_stepwell_done_config

Now here are our new parameters.ini file

changed_params_ini

working with git. putting the site to github.

Now we need to put the site to github I will show you here the NetBeans integration with Git, but I really prefer the command line way from Git Bash (MsysGit). First I will create a repository at Github. I’ll name FirstSymfony2App.

Next we’ll add a .gitignore file to our project. But what is to ignore actually ? Well I didn’t knew it either so I found a typical ignore file for Symfony2 project. So I found it in http://github.com/github/gitignore/blob/master/Symfony2.gitignore.

# Bootstrap
app/bootstrap*

# Symfony directories
vendor/*
*/logs/*
*/cache/*
web/uploads/*
web/bundles/*

# Configuration files
app/config/parameters.ini

Copy it and create this file in our project.

Now we can initialize the Git repository directly from NetBeans. Select the project. Right click go to Versioning –> Initialize Git Repository.

init_git

  • Now we can add the files to Git by “Git –> Add” command.
  • Also we can commit now by right click Project –> “Git –> Commit”.
  • Also we can see already made commits by “Git –> Show History” command

Now lets push the contents of our site to Github. First we’ll need to use a remote site to which to push. Ok let’s execute Git –> Remote –> Push command.

2012-01-19_15422012-01-19_1543

2012-01-19_1544

That’s all folks, our project is on Github. You can see it here https://github.com/Monomachus/FirstSymfony2App

PULLING Project From GiTHUB AND RUNNING IT

Now let’s see the perspective of another developer who wants to use/participate in the project. For the sake of the experiment I will delete all the sources and will use MsysGit to do all Git-related stuff, though I think I could somehow use NetBeans for it.

I will clone the repository directly into XAMPP server, htdocs folder. Also I will name the folder FirstApp to avoid specific problems. Using Git Bash tool run this command

$ git clone https://Monomachus@github.com/Monomachus/FirstSymfony2App.git FirstApp

Import the project into NetBeans using File –> Open Project command. Now start Apache and MySql and run the project. We will also need to specify the project URL : http://localhost/FirstApp/web/app_dev.php .

Now we get an error:

Warning: require_once(D:\xampp_server\htdocs\FirstApp\web/../app/bootstrap.php.cache) [function.require-once]: failed to open stream: No such file or directory in D:\xampp_server\htdocs\FirstApp\web\app_dev.php on line 17  
Fatal error: require_once() [function.require]: Failed opening required 'D:\xampp_server\htdocs\FirstApp\web/../app/bootstrap.php.cache' (include_path='.;D:\xampp_server\php\PEAR') in D:\xampp_server\htdocs\FirstApp\web\app_dev.php on line 17

2012-01-19_1604

This error is caused by the fact that in our .gitignore file there is this line app/bootstrap*  and this means that our bootstrap.php.cache file was ignored and not committed to the Github. So the question is how can we regenerate this file ? Well, thanks to Beeton from IRC channel #symfony from Freenode, I found out that we can generate it using the

php bin/vendors install

command and that vendor/bundles/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php is the file that actually creates it.

But before you run that command please note that we also do not have the app/config/parameters.ini file because it is also in our .gitignore file. Is it really a good idea ? Yes it is if you work with other people, it means that your MySql database configuration can actually differ from your mate’s configuration.

So where do you get the sample file, well almost always in open source world the answer is Github. Smile The link to the sample file https://github.com/symfony/symfony-standard/blob/v2.0.9/app/config/parameters.ini

Copy that file and add it to the app/config folder. Modify it and than run the command php bin/vendors install

$ php bin/vendors install
> Installing/Updating symfony
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/symfony'...
remote: Counting objects: 109718, done.
remote: Compressing objects: 100% (35141/35141), done.
remote: Total 109718 (delta 68210), reused 102521 (delta 62139)
Receiving objects: 100% (109718/109718), 16.38 MiB | 3.49 MiB/s, done.
Resolving deltas: 100% (68210/68210), done.
f842739d58b649ffbe6543b2eff520327373029d
HEAD is now at 3e9d937 updated VERSION for 2.0.9
> Installing/Updating twig
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/twig'...
remote: Counting objects: 9859, done.
remote: Compressing objects: 100% (2606/2606), done.
remote: Total 9859 (delta 6399), reused 9540 (delta 6122)
Receiving objects: 100% (9859/9859), 1.28 MiB | 444 KiB/s, done.
Resolving deltas: 100% (6399/6399), done.
96596d5c7f6920dc59985c1cba531ae20715baf4
HEAD is now at 5bba149 prepared the 1.5.1 release
> Installing/Updating monolog
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/monolog'...
remote: Counting objects: 1384, done.
remote: Compressing objects: 100% (548/548), done.
remote: Total 1384 (delta 748), reused 1322 (delta 695)Receiving objects:  94% (
Receiving objects:  96% (1329/1384), 52.00 KiB | 90 KiB/s
Receiving objects: 100% (1384/1384), 174.72 KiB | 90 KiB/s, done.
Resolving deltas: 100% (748/748), done.
8e11234066280685e903ea6dcc0d304cd1aec9b9
HEAD is now at b704c49 Only send FirePHP headers to browser advertising support
for it in their user agent
> Installing/Updating doctrine-common
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/doctrine-common'...
remote: Counting objects: 57783, done.
remote: Compressing objects: 100% (14404/14404), done.
remote: Total 57783 (delta 40513), reused 57588 (delta 40349)
Receiving objects: 100% (57783/57783), 15.34 MiB | 834 KiB/s, done.
Resolving deltas: 100% (40513/40513), done.
38c854c37d20b1f67c979772089b2cd30908bcb6
HEAD is now at b886898 Release 2.1.4
> Installing/Updating doctrine-dbal
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/doctrine-dbal'...
remote: Counting objects: 59701, done.
remote: Compressing objects: 100% (15249/15249), done.
remote: Total 59701 (delta 41906), reused 59291 (delta 41520)Receiving objects:


Resolving deltas: 100% (41906/41906), done.
2a9e9943f33610bfde4637abeafe00edd201803c
HEAD is now at ae358bd Merge remote branch 'origin/2.1.x' into 2.1.x
> Installing/Updating doctrine
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/doctrine'...
remote: Counting objects: 69262, done.
remote: Compressing objects: 100% (17611/17611), done.
remote: Total 69262 (delta 48424), reused 68330 (delta 47567)
Receiving objects: 100% (69262/69262), 17.08 MiB | 2.61 MiB/s, done.
Resolving deltas: 100% (48424/48424), done.
febfe35c2315a20534630aa9e5b9c72a0047f569
HEAD is now at da0e343 Release 2.1.5
> Installing/Updating swiftmailer
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/swiftmailer'...
remote: Counting objects: 9620, done.
remote: Compressing objects: 100% (3288/3288), done.
remote: Total 9620 (delta 5536), reused 9458 (delta 5388)
 (9524/9620), 4.93 MiB | 876 KiB/s
Receiving objects: 100% (9620/9620), 5.04 MiB | 889 KiB/s, done.
Resolving deltas: 100% (5536/5536), done.
0243dc3b18c784adda72e71f6bd34f11fef69b4b
HEAD is now at 982b4c9 prepared the 4.1.5 release
> Installing/Updating assetic
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/assetic'...
remote: Counting objects: 4714, done.
remote: Compressing objects: 100% (1665/1665), done.
remote: Total 4714 (delta 2787), reused 4492 (delta 2600)Receiving objects:  99%

Receiving objects: 100% (4714/4714), 540.18 KiB | 251 KiB/s, done.
Resolving deltas: 100% (2787/2787), done.
e15a13fe4782caa6566c7f0c34ae10badaf85361
HEAD is now at f829ad2 updated changelog
> Installing/Updating twig-extensions
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/twig-extensions'...
remote: Counting objects: 297, done.
remote: Compressing objects: 100% (148/148), done.
remote: Total 297 (delta 108), reused 270 (delta 84)Receiving objects:   7% (21/
Receiving objects:   8% (24/297)
Receiving objects: 100% (297/297), 40.25 KiB, done.
Resolving deltas: 100% (108/108), done.
a05ab5ed18a51ae45f3dcc2d0c4ec9b3a6386987
> Installing/Updating metadata
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/metadata'...
remote: Counting objects: 249, done.
remote: Compressing objects: 100% (178/178), done.
remote: Total 249 (delta 118), reused 128 (delta 32)Receiving objects:  91% (227
Receiving objects:  93% (232/249)
Receiving objects: 100% (249/249), 33.70 KiB, done.
Resolving deltas: 100% (118/118), done.
7d97f1725063f04ef1894a86740b261daf229b89
HEAD is now at 8717ad2 release 1.0.0
> Installing/Updating SensioFrameworkExtraBundle
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor//bundles/Sensio/Bundle/Fram
eworkExtraBundle'...
remote: Counting objects: 1064, done.
remote: Compressing objects: 100% (518/518), done.
remote: Total 1064 (delta 582), reused 969 (delta 500)Receiving objects:  94% (1
Receiving objects:  96% (1022/1064), 132.00 KiB | 74 KiB/s
Receiving objects: 100% (1064/1064), 132.52 KiB | 74 KiB/s, done.
Resolving deltas: 100% (582/582), done.
55de01d34c5b95ee07bd511d06e0b171af5fe9ba
HEAD is now at 1c7e92f fixed tests config
> Installing/Updating JMSSecurityExtraBundle
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor//bundles/JMS/SecurityExtraB
undle'...
remote: Counting objects: 1665, done.
remote: Compressing objects: 100% (718/718), done.
remote: Total 1665 (delta 880), reused 1595 (delta 810)
Receiving objects: 100% (1665/1665), 273.00 KiB | 228 KiB/s, done.
Resolving deltas: 100% (880/880), done.
4dc8223afa9a38cc467e0a858ef5741e6cc3987d
HEAD is now at 541a4c2 Merge pull request #36 from everzet/patch-1
> Installing/Updating SensioDistributionBundle
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor//bundles/Sensio/Bundle/Dist
ributionBundle'...
remote: Counting objects: 423, done.
remote: Compressing objects: 100% (201/201), done.
remote: Total 423 (delta 211), reused 414 (delta 206)Receiving objects:  70% (29

Receiving objects: 100% (423/423), 60.86 KiB | 87 KiB/s, done.
Resolving deltas: 100% (211/211), done.
f00c99854ff161b006a200d8dffa0013981d5373
HEAD is now at 20b66a4 fixed version in composer.json
> Installing/Updating SensioGeneratorBundle
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor//bundles/Sensio/Bundle/Gene
ratorBundle'...
remote: Counting objects: 651, done.
remote: Compressing objects: 100% (302/302), done.
remote: Total 651 (delta 343), reused 609 (delta 317)Receiving objects:  77% (50
2/651), 76.00 KiB | 130 KiB/s
Receiving objects: 100% (651/651), 115.97 KiB | 130 KiB/s, done.
Resolving deltas: 100% (343/343), done.
67bf607b41f930f93f2032d069be535ecaa21730
HEAD is now at dd37fc4 merged branch gnomii/use_filesystem_component (PR #88)
> Installing/Updating AsseticBundle
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor//bundles/Symfony/Bundle/Ass
eticBundle'...
remote: Counting objects: 1741, done.
remote: Compressing objects: 100% (544/544), done.
remote: Total 1741 (delta 1056), reused 1671 (delta 992)Receiving objects:  94%

Receiving objects: 100% (1741/1741), 229.34 KiB | 86 KiB/s, done.
Resolving deltas: 100% (1056/1056), done.
ae7f6f4dc252d37c686584576cc92f07b092d06a
HEAD is now at 41b5913 Merge pull request #27 from stof/disable_profiler
Installing assets for Symfony\Bundle\FrameworkBundle into D:\xampp_server\htdocs
\FirstApp/web/bundles/framework
Installing assets for Acme\DemoBundle into D:\xampp_server\htdocs\FirstApp/web/b
undles/acmedemo
Installing assets for Symfony\Bundle\WebProfilerBundle into D:\xampp_server\htdo
cs\FirstApp/web/bundles/webprofiler
Installing assets for Sensio\Bundle\DistributionBundle into D:\xampp_server\htdo
cs\FirstApp/web/bundles/sensiodistribution
Clearing the cache for the dev environment with debug true

After these manipulations we can finally run the sample application.

2012-01-19_1644

Today we learned how to create and run your first Symfony2 project and push and pull it to/from Github.

Hope you liked it, if you have any concerns, ideas for posts, suggestions please post it here. Good coding guys!

Setting up Windows environment for Symfony2 developing with NetBeans, XAMPP and Git

[UPDATE] This is a series of post in the next one I’ll show you first Symfony2 app and how to make it work with Git. Second post link: Git and first Symfony2 project in NetBeans

Hi,

For a long time there was no sign of me here, but I hope this will change… So what do I do these days, well I want to go in Symfony2 to see how it feels like… Lots of guys were telling me PHP is way faster in development than in Java or .NET Web development so I want to try it out too.

So what do we actually need ?

XAMPP

No problem with that one. Get the latest version, install it but please don’t install MySql and Apache as services.  Than add a system environment variable like XAMPP_HOME for example and than add

;%XAMPP_HOME%\php;%XAMPP_HOME%\mysql\bin\

to Path environment variable. Now you should be able to check your PHP version from command line.

Try it now

XDEBUG based on your own phpinfo

A friend of mine showed me a wonderful site for getting your own DLL that is needed for your exactly configuration.

But first start your Apache server from your XAMPP control panel. Go to http://localhost/xampp/phpinfo.php and go get view source and copy all the HTML. Now go to http://www.xdebug.org/find-binary.php and insert the HTML into the textarea. Click on “Analyze my phpinfo output” button. And there you go you have your own DLL to download. Download it and put it into your php/ext folder

find_xdebug_binaryfind_xdebug_dll

Now go to your php.ini location and add these lines + the line starting with zend_extension

xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
zend_extension = D:\xampp_server\php\ext\php_xdebug-2.1.2-5.3-vc9.dll

Now your machine should be ready for debug.


INSTALL mSYSGIT – GIT FOR Windows

Go and get the latest msysgit from and install it http://code.google.com/p/msysgit/downloads/list

2012-01-19_1144

SYMFONY2 Package

Go to http://symfony.com/download

Download the latest version in a .ZIP package. At the time of writing this it was Symfony Standart 2.0.9.zip

Make a separate folder and put this zip into it (in my case symfony2_php_sources). Also unzip it into another folder. (in my case symfony2_php_sources/Symfony).

IDE

Well we have some options like Eclipse and NetBeans also some support in PHPStorm, but I choose NetBeans 7.1.

There are a number of reasons why I chose it:

  • Out of box support for YAML
  • Support for Symfony2 (plugin)
  • Support for Twig (templating engine in Symfony2) also plugin
  • More user friendly than Eclipse (I guess someone could argue that, but I worked in Eclipse for 1 year).

So let’s starts go to  http://netbeans.org/downloads/

2012-01-19_1035

Add plugin for Symfony2. Go to Tools –> Plugins –> Tab Available Plugins –> click “Reload Catalog” –: in Search box input “symfony2” and press Enter. Now there should be a plugin there, called PHP Symfony2 Framework. Install it and restart NetBeans.

Add plugin for Twig. For now it is available for download from https://github.com/blogsh/Twig-netbeans/downloads as a NBM file. Download the latest file.

And install it in NetBeans. 

Now let’s tweak it a little bit. Go to Tools –> Options –> PHP.

Here we’ll have a little fun go to General tab –> Indicate your php.exe location in XAMPP. Also add in Global include path unpacked Symfony2 sources.

Go to Unit Testing tab and indicate the location of your phpunit.bat

Go to Symfony2 tab and indicate the location of the downloaded Symfony2 zip file.

Here is the cumulative actions screenshot

THAT’S ALL. Now your machine is configured.

Next time I’ll show you how to work with your first Symfony2 project and Git.

If you have any concerns, suggestions, ideas for blog posts please comment here.

Monday, August 15, 2011

Attendance sample application in PlayFramework – Part 1

Hi,

Recently I found out a new Java framework which actually suck less than Java overall I think, because it uses the same kind of system as Rails in Ruby.

For now I won’t go in too much details, but if you’d like to see the bootstrapping process for a project, and how to integrate with Secure module from PlayFramework, Attendance app, the application I’m doing for my buddy Teejay from Nigeria, is a good example.

I've showed in this podcast how to create a sample PlayFramework application. Import a new site template into it, create a User model, import Secure module from PlayFramework and add authentication to the app. Set up the default database to MySQL.
Created sample Attendance page, and played with Groovy templates a little bit.
In the second part I will continue to work on Attendance page, and admin part.

 

Hope soon the second part of the application will be available too.

Thursday, January 6, 2011

Git in Action

Hi, guys found this amazing and quite simple video about using Git. Take a look.

Git Screencast: Git in Action from Ralf Ebert on Vimeo.

Give thumbs up to this post if you liked it and please comment about what do you also want to see in my blog.

Saturday, December 11, 2010

Ruby Challenge 2010: Creating first application and working with Git

Hi all one more time,

Last time we stopped by installing Rails. Let’s check one more time it’s current version

C:\Users\Monomachus>rails --version
Rails 3.0.3

You can notice that from the last time we talked about it Rails version changed from 3.0.1 to 3.0.3. That’s because I’ve updated my system.

Now lets create a new application with Rails. We can do it by using “rails new name_of_the_application” command

D:\rails_tutorial_project>rails new first_application
      create
      create  README
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/mailers
      create  app/models
      create  app/views/layouts/application.html.erb
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/secret_token.rb
      create  config/initializers/session_store.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  doc
      create  doc/README_FOR_APP
      create  lib
      create  lib/tasks
      create  lib/tasks/.gitkeep
      create  log
      create  log/server.log
      create  log/production.log
      create  log/development.log
      create  log/test.log
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/index.html
      create  public/robots.txt
      create  public/images
      create  public/images/rails.png
      create  public/stylesheets
      create  public/stylesheets/.gitkeep
      create  public/javascripts
      create  public/javascripts/application.js
      create  public/javascripts/controls.js
      create  public/javascripts/dragdrop.js
      create  public/javascripts/effects.js
      create  public/javascripts/prototype.js
      create  public/javascripts/rails.js
      create  script
      create  script/rails
      create  test
      create  test/fixtures
      create  test/functional
      create  test/integration
      create  test/performance/browsing_test.rb
      create  test/test_helper.rb
      create  test/unit
      create  tmp
      create  tmp/sessions
      create  tmp/sockets
      create  tmp/cache
      create  tmp/pids
      create  vendor/plugins
      create  vendor/plugins/.gitkeep

Will get to each of those files in this series posts, this is what I hope at least to achieve.

Tip of the day: .gitignore file is used to let git know what kind of files we don’t want to add/commit to repository 

Ok, so we got everything created now and rails made for us a brand new application which should already work so let’s try it with “rails server” command. First we need to cd into the new created directory.

And I got error at first

railsStartError

And these errors in command line

D:\rails_tutorial_project\first_application>rails server
C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/sqlite3-ruby-1.3.2-x86-mingw32/lib/sq
lite3.rb:6:in `require': no such file to load -- sqlite3/sqlite3_native (LoadErr
or)
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/sqlite3-ruby-1.3.2-x86-m
ingw32/lib/sqlite3.rb:6:in `rescue in <top (required)>'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/sqlite3-ruby-1.3.2-x86-m
ingw32/lib/sqlite3.rb:2:in `<top (required)>'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundle
r/runtime.rb:64:in `require'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundle
r/runtime.rb:64:in `block (2 levels) in require'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundle
r/runtime.rb:62:in `each'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundle
r/runtime.rb:62:in `block in require'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundle
r/runtime.rb:51:in `each'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundle
r/runtime.rb:51:in `require'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundle
r.rb:112:in `require'
        from D:/rails_tutorial_project/first_application/config/application.rb:7
:in `<top (required)>'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails
/commands.rb:28:in `require'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails
/commands.rb:28:in `block in <top (required)>'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails
/commands.rb:27:in `tap'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails
/commands.rb:27:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

After poking a little bit on forums I saw that I need to download the latest version of Sqlite dll’s and put them into my “ruby\bin” folder. Ok no problems, let’s do it. So you can download it here.

sqliteDownloads

Downloaded, unziped, xcopied into ruby\bin folder. Let’s try again.

D:\rails_tutorial_project\first_application>rails server
=> Booting WEBrick
=> Rails 3.0.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2010-12-11 10:00:40] INFO  WEBrick 1.3.1
[2010-12-11 10:00:40] INFO  ruby 1.9.2 (2010-08-18) [i386-mingw32]
[2010-12-11 10:00:44] INFO  WEBrick::HTTPServer#start: pid=3560 port=3000

Ok so now that works fine.

runningServer

P.S. Anyone knows how to run the server and then to detach in windows it also gives me an error in Windows when I try to use “rails server –d”

D:\rails_tutorial_project\first_application>rails server -d
=> Booting WEBrick
=> Rails 3.0.3 application starting in development on http://0.0.0.0:3000
C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_suppor
t/core_ext/process/daemon.rb:3:in `fork': fork() function is unimplemented on th
is machine (NotImplementedError)
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/
active_support/core_ext/process/daemon.rb:3:in `daemon'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/serv
er.rb:262:in `daemonize_app'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/serv
er.rb:202:in `start'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails
/commands/server.rb:65:in `start'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails
/commands.rb:30:in `block in <top (required)>'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails
/commands.rb:27:in `tap'
        from C:/rubies/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails
/commands.rb:27:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'
WORKING WITH GIT

Ok now let’s try to work a little bit with git. I’ll be using now the “Git Bash” command line.

$ git init                // initilize the repository
$ git add .               // adds everything to repository
$ git commit -m "First commit" // make initial commit

So here everything should be clear. In git commit command –m means specifying message.

Now we can check the logs

Monomachus@MONOMACHUS-PC /d/rails_tutorial_project/first_application (master)
$ git log
commit 24d181eef79f1c6bd28898bcb0a587ff04a73dca
Author: unknown <Monomachus@.(none)>
Date:   Sat Dec 11 10:12:55 2010 +0200

    First commit

Now let’s see how can we checkout but first let’s delete some important file (Gemfile for example) and verify the status of git.
Monomachus@MONOMACHUS-PC /d/rails_tutorial_project/first_application (master)
$ rm Gemfile*

Monomachus@MONOMACHUS-PC /d/rails_tutorial_project/first_application (master)
$ ls
README    app     config.ru  doc  log     script  tmp
Rakefile  config  db         lib  public  test    vendor

Monomachus@MONOMACHUS-PC /d/rails_tutorial_project/first_application (master)
$ git status
# On branch master
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    Gemfile
#       deleted:    Gemfile.lock
#
no changes added to commit (use "git add" and/or "git commit -a")

Monomachus@MONOMACHUS-PC /d/rails_tutorial_project/first_application (master)
$ git checkout -f

Monomachus@MONOMACHUS-PC /d/rails_tutorial_project/first_application (master)
$ ls
Gemfile       README    app     config.ru  doc  log     script  tmp
Gemfile.lock  Rakefile  config  db         lib  public  test    vendor

 

So you can see here that using “git status” command we checked out the status of repository and with “git checkout –f” command we made a forced checkout and restored everything as it was before.

It’s all for today. Next time we’ll play a little with Github and Heroku. I hope you liked it.

 

Tuesday, November 2, 2010

Ruby Challenge 2010: Installing Ruby and its tools on Windows

Hi,

Today I decided to install all the prerequisites and to show you how I’ve done this, may be for some people it will be useful. And I’m doing it by reproducing the Rails 3.0 tutorial but for Windows.

1. Text editor / IDE

From various IDEs and Unix-style editors like vi or emacs or whatever. I decided to go with a full IDE solution so … the nominees are

  1. Aptana Studio 2.0 – standalone version
  2. NetBeans 6.9.1 – ruby version
  3. RubyMine 2.0 – from JetBrains (creators of Resharper, TeamCity and a lot of other cool software for programmers).

I wanted to go with RubyMine because I already know the difference Resharper brings in my development process, but it’s a 30-days trial, and I don’t want to switch to something new in next few months, so no. I don’t have previous experience with Aptana Studio, and may be I will try it some day, but I had a pleasant experience with NetBeans so for now I will go with that.

NetBeansDownload

2. Git

Ruby community uses intensely a version control system called Git, so I will install it too. For windows part it is very simple. You go to http://code.google.com/p/msysgit/. Click “Downloads” and choose current version Git.exe installer.

DownloadingGitForWindows

Install process is Windows-style - very simple as well. We don’t have to manually compile something or edit, everything goes quite simple.

InstallingGit

3. Installing Ruby

First we need to be sure that our system doesn’t already has Ruby installed. Let’s try it.

C:\Users\user_name>ruby -v
'ruby' is not recognized as an internal or external command,
operable program or batch file.

Well looks like I don’t have it installed. Not a problem. First we’ll install Ruby 1.8.7 which works well with Rails 2.3. We’ll go to Download Ruby page search for “Ruby on Windows” section and select Ruby 1.8.7-p302 RubyInstaller. Installation goes smoothly. I associated my *.rb files with ruby and added Ruby executables to my path.

Now we see this in our command line:

C:\Users\user_name>ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
4. Installing and using Pik

pikScreenshot

What is Pik? Pik is a Windows alternative to Ruby Version Manager (RVM) which allows us to have multiple Ruby versions installed at the same time, as I said before we need Ruby 1.8.7 to work with Rails 2.3 and Ruby 1.9.2 to work with Rails 3.0.1 and Pik will help us in dealing with this. You can download Pik from github. Also be sure to check its Wiki page “Usage”.

Now when we run the first time pik it adds the default Ruby path which right now points to version 1.8.7. I also set Pik default install directory to “C:\Rubies” and I also show how to add an existing ruby installation to pik with the “add” command.

C:\Users\user_name>pik
** Adding:  187: ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
 Located at:  C:\Rubies\Ruby187\bin
Usage: pik command [options]

To get help with a command

  pik help (command)

To list all commands and descriptions:

  pik help commands

    -V, --version                    Pik version
    -d, --debug                      Outputs debug information

C:\Users\user_name>pik config installs="C:\Rubies"

C:\Users\user_name>pik add C:\Rubies\Ruby-1.9.2dev-p3-i386-mingw32\bin
** Adding:  192: ruby 1.9.2dev (2010-05-31) [i386-mingw32]
 Located at:  C:\Rubies\Ruby-1.9.2dev-p3-i386-mingw32\bin

Next I show how to install a Ruby version using “install” command. In my particular case I installed IronRuby specifying the version, and then not specifying it. When you don’t specify it then Pik downloads the latest version. (although at the moment the latest version of IronRuby is 1.1.1, don’t know what is wrong there). Than I show how to list all the available Rubies installations (note that * marks the default ruby used at the moment), how to remove a Ruby install from Pik management, and how to switch to another Ruby installation.

C:\Users\user_name>pik install IronRuby 1.0.0
** Downloading:  http://rubyforge.org/frs/download.php/69853/ironruby-1.0.0rc.zi
p
   to:  C:\Users\user_name\.pik\downloads\ironruby-1.0.0rc.zip

ironruby-1.0.0rc.zip: 100% |ooooooooooooooooooo|   4.7MB/  4.7MB Time: 00:00:06

** Extracting:  C:\Users\user_name\.pik\downloads\ironruby-1.0.0rc.zip
   to:  C:\rubies\IronRuby-100rc
done

Couldn't find a Ruby version at C:\rubies\IronRuby-100rc\bin

C:\Users\user_name>pik add C:\Rubies\IronRuby-100rc\ironruby\bin
** Adding:  100: IronRuby 1.0.0.0 on .NET 2.0.50727.4454
 Located at:  C:\Rubies\IronRuby-100rc\ironruby\bin

C:\Users\user_name>pik install IronRuby
** Downloading:  http://rubyforge.org/frs/download.php/70181/ironruby-1.0v4.zip

   to:  C:\Users\user_name\.pik\downloads\ironruby-1.0v4.zip

ironruby-1.0v4.zip: 100% |ooooooooooooooooooooo|   2.9MB/  2.9MB Time: 00:00:04

** Extracting:  C:\Users\user_name\.pik\downloads\ironruby-1.0v4.zip
   to:  C:\rubies\IronRuby-10v4
done

** Adding:  100: IronRuby 1.0.0.0 on .NET 4.0.30319.1
 Located at:  C:\rubies\IronRuby-10v4\bin

C:\Users\user_name>pik remove C:\Rubies\IronRuby-100rc\ironruby\bin

Quitting...

C:\Users\user_name>pik help commands

  add             Adds another ruby location to pik.
  benchmark|bench Runs bencmarks with all versions that pik is aware of.
  config          Adds/modifies configuration options.
  default         Switches back to the default settings.
  devkit          Configures devkit settings
  gem             Runs the gem command with all versions that pik is aware of.
  gemsync         Synchronizes gems from the version specified to the current ve
rsion.
  help            Displays help information.
  implode         Removes your pik configuration.
  info|checkup|cu Displays information about the current ruby version.
  install|in      Downloads and installs different ruby versions.
  list|ls         Lists ruby versions that pik is aware of.
  rake            Runs the rake command with all versions that pik is aware of.
  remove|rm       Removes a ruby location from pik.
  ruby|rb         Runs ruby with all versions that pik is aware of.
  run             Runs command with all versions of ruby that pik is aware of.
  tag             Adds the given tag to the current version.
  tags            Runs the pik command against the given tags.
  uninstall|unin  Deletes a ruby version from the filesystem and removes it from
 Pik.
  update|up       updates pik.
  use|switch|sw   Switches ruby versions based on patterns.

For help on a particular command, use 'pik help COMMAND'.

C:\Users\user_name>pik list
  100: IronRuby 1.0.0.0 on .NET 2.0.50727.4454
  100: IronRuby 1.0.0.0 on .NET 4.0.30319.1
* 187: ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
  192: ruby 1.9.2dev (2010-05-31) [i386-mingw32]

C:\Users\user_name>pik remove 100
Select which Ruby you want:
1. 100: IronRuby 1.0.0.0 on .NET 2.0.50727.4454
2. 100: IronRuby 1.0.0.0 on .NET 4.0.30319.1
?  1
Are you sure you'd like to remove '100: IronRuby 1.0.0.0 on .NET 2.0.50727.4454'
?  |yes|

100: IronRuby 1.0.0.0 on .NET 2.0.50727.4454 removed.

C:\Users\user_name>pik use 192

C:\Users\user_name>pik list
  100: IronRuby 1.0.0.0 on .NET 4.0.30319.1
  187: ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
* 192: ruby 1.9.2dev (2010-05-31) [i386-mingw32]

The only thing that I can’t find is an alternative to RVM –create command which is often convenient to create separate gemsets. 

5. Installing and using RubyGems

gems

UPDATE: After installing any version of Ruby you already should have RubyGems installed. You can check it up by using “gem –v” command. I talk about installing RubyGems here just because I was having errors with default installation of gem. 

After everything done I already have gems installed but it has some errors so I will download the latest version from here. After that you unpack it somewhere cd into its directory and say

ruby setup.rb

Now gems should be installed. Next thing you could do is see what is your Gems environment with “gem env” command, or see the gems sources with “gem sources” command. Finally you could do “gem list” for list of local gems, “gem list –r” for remote gems, and “gem list STRING” which will bring you the list of gems starting with string.

6. Installing Rails

rails

Now having Gems installed it’s really easy to install Rails. You should just say

gem install rails

Or

gem install rails --version 3.0.1

Now everything should be prepared and installed. You can verify it by writing “rails –v” and have the rails version.

Well that’s a lot of things to do, especially if you’re used already with Windows way of installing things. Hope this post will help someone.

Next time we’ll do our first application in RoR (Ruby on Rails), so stay tuned!