Rails 3: How to “redirect_to” in Ajax call?


Replaced below redirect method

redirect_to(:controller => 'jobs', :action => 'index')

with this:

render :js => "window.location = '/jobs/index'"

and it works fine!

Else

Pass static url to link

= link_to ‘Set as application form’, “org_form_and_documents?id=#{params[:id]}”, :onclick => “set_as_app()”, :class => “active”

function set_as_app()
  {
      var IDs = [];
      $(“.form_check”).each(function()
      {
        var each_id = ‘#’+this.id;        
        if ($(each_id).attr(‘checked’))
        {            
            IDs.push(this.id);
            $.ajax({
                 url: “/organizations/change_form”,
                 data: { form_id: this.id, org_id: $(‘#org’).val(), season: $(‘#season’).val()},
                 cache: false,                      
            })
        }                  
      });
      
  }
I hope, it will help..!!!

 

 

 

Advertisements

Every thing with git


1. Track status of modified file.

pravinmishra@ubuntu:~/workSpace/every_thing_with_git$ git status -s
M app/assets/stylesheets/scaffolds.css.scss

2.Track difference in file.

pravinmishra@ubuntu:~/workSpace/every_thing_with_git$ git diff
diff –git a/app/views/orders/index.html.erb b/app/views/orders/index.html.erb
index d2c3f03..9b9bd01 100644
— a/app/views/orders/index.html.erb
+++ b/app/views/orders/index.html.erb
@@ -26,4 +26,4 @@

<h2>nothing</h2>

-<h1>nothing</h1>
+<h1>pravinmishra88@gmail.com</h1>

3.Shows abbreviated commits and a nice graph of branches with the messages on a single line.

pravinmishra@ubuntu:~/workSpace/every_thing_with_git$ git config –global alias.lol “log –pretty=oneline –abbrev-commit –graph –decorate”
pravinmishra@ubuntu:~/workSpace/every_thing_with_git$ git lol
*   84cdcd1 (HEAD, master) Merge branch ‘blue’
|\
| * f534661 (blue) yellow
* |   2d06b84 Merge branch ’email’
|\ \
| |/
|/|
| * 520585c (email) change email
* | 85a0703 blue background
|/
* b0f4f06 (rspec-test) few changes
* 1ff053a (origin/master) first commit

4. Stage the changes. In order to begin tracking a new file, you use the command git add.

git add (file)

5. Review your changes. The main tool you use to determine which files are in which state is the git
status command.

git status/diff

6.Stage and commit

git commit -a

7. Get a Reference(The ref in the URL must be formatted as heads/branch, not just branch. )

pravinmishra@ubuntu:~/workSpace/every_thing_with_git$ find .git/refs
.git/refs
.git/refs/tags
.git/refs/heads
.git/refs/heads/email
.git/refs/heads/blue
.git/refs/heads/master
.git/refs/heads/rspec-test
.git/refs/remotes
.git/refs/remotes/origin
.git/refs/remotes/origin/master

8.Ignoring Files

Often, you’ll have a class of files that you don’t want Git to automatically
add or even show you as being untracked. These are generally automatically
generated files such as log files or files produced by your build system. In such
cases, you can create a file listing patterns to match them named .gitignore.

$ cat .gitignore
*.[oa]
*~

9.Remove file
To remove a file from Git, you have to remove it from your tracked files (more
accurately, remove it from your staging area) and then commit. The git rm
command does that and also removes the file from your working directory so
you don’t see it as an untracked file next time around.
$ git rm file_name

10. Moving file

If you want to rename a file in Git, you can run something like
$ git mv file_from file_to

11. Viewing the commit history

-See all commit by date and user

$ git log

-options is -p, which shows the diff introduced in each commit.
$ git log -p -2
Merge: 2d06b84 f534661
Author: Pravin  Mishra <diatm.pravin.it.07.27@gmail.com>
Date:   Thu Sep 6 23:48:41 2012 +0530

Merge branch ‘blue’

commit f5346619e66f9e59ed6141ba46ec7bd899d82de0
Author: Pravin  Mishra <diatm.pravin.it.07.27@gmail.com>
Date:   Thu Sep 6 23:48:05 2012 +0530

yellow

diff –git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss
index 99d7183..8a4b162 100644
— a/app/assets/stylesheets/scaffolds.css.scss
+++ b/app/assets/stylesheets/scaffolds.css.scss
@@ -1,5 +1,5 @@
body {
–  background-color: blue;
+  background-color: yellow;
color: #333;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;

-if you want to see some abbreviated stats for each commit, you can use the –stat option:
$ git log –stat
commit 84cdcd11c41c66897ec8327615028742071ae1f8
Merge: 2d06b84 f534661
Author: Pravin  Mishra <diatm.pravin.it.07.27@gmail.com>
Date:   Thu Sep 6 23:48:41 2012 +0530

Merge branch ‘blue’

commit f5346619e66f9e59ed6141ba46ec7bd899d82de0
Author: Pravin  Mishra <diatm.pravin.it.07.27@gmail.com>
Date:   Thu Sep 6 23:48:05 2012 +0530

yellow

app/assets/stylesheets/scaffolds.css.scss |    2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

commit 2d06b8425bcb28592835ce1133f500e243770cb6
Merge: 85a0703 520585c
Author: Pravin  Mishra <diatm.pravin.it.07.27@gmail.com>
Date:   Thu Sep 6 23:43:54 2012 +0530

Merge branch ’email’

-This option changes the log output to formats other than the default.
$ git log –pretty=oneline
84cdcd11c41c66897ec8327615028742071ae1f8 Merge branch ‘blue’
f5346619e66f9e59ed6141ba46ec7bd899d82de0 yellow
2d06b8425bcb28592835ce1133f500e243770cb6 Merge branch ’email’
520585c934bad43db8a390333c103c552a393f9e change email
85a070328bff3bf5835f7b27389899a00b817102 blue background
b0f4f06fae59165f0f797b5e056d259726b3d455 few changes
1ff053a7037e907af4a60cfdd34eca29da75f6f3 first commit

-This option adds a nice little ASCII graph showing your branch and merge history, which we can see our copy of the Grit project repository:
$ git log –pretty=format:”%h %s” –graph
*   84cdcd1 Merge branch ‘blue’
|\
| * f534661 yellow
* |   2d06b84 Merge branch ’email’
|\ \
| |/
|/|
| * 520585c change email
* | 85a0703 blue background
|/
* b0f4f06 few changes
* 1ff053a first commit

12.Limit log output

We can time-limiting options such as –since and –until are very useful.
$ git log –since=2.weeks
commit 84cdcd11c41c66897ec8327615028742071ae1f8
Merge: 2d06b84 f534661
Author: Pravin  Mishra <diatm.pravin.it.07.27@gmail.com>
Date:   Thu Sep 6 23:48:41 2012 +0530

Merge branch ‘blue’

commit f5346619e66f9e59ed6141ba46ec7bd899d82de0
Author: Pravin  Mishra <diatm.pravin.it.07.27@gmail.com>
Date:   Thu Sep 6 23:48:05 2012 +0530

12. Undoing Things

-One of the common undos takes place when you commit too early and possibly forget to add some files, or you mess up your commit message. If you want to try that commit again, you can run commit with the –amend option:

$ git commit –amend

Unstaging a Staged File
$ git status
# On branch master
# Your branch is ahead of ‘origin/master’ by 1 commit.
#
# Changes not staged for commit:
#   (use “git add <file>…” to update what will be committed)
#   (use “git checkout — <file>…” to discard changes in working directory)
#
#    modified:   README.rdoc
#    modified:   Rakefile
#
no changes added to commit (use “git add” and/or “git commit -a”)
pravinmishra@ubuntu:~/workSpace/every_thing_with_git$ git add .
pravinmishra@ubuntu:~/workSpace/every_thing_with_git$ git status
# On branch master
# Your branch is ahead of ‘origin/master’ by 1 commit.
#
# Changes to be committed:
#   (use “git reset HEAD <file>…” to unstage)
#
#    modified:   README.rdoc
#    modified:   Rakefile
#
pravinmishra@ubuntu:~/workSpace/every_thing_with_git$ git reset HEAD Rakefile
Unstaged changes after reset:
M    Rakefile
pravinmishra@ubuntu:~/workSpace/every_thing_with_git$ git status
# On branch master
# Your branch is ahead of ‘origin/master’ by 1 commit.
#
# Changes to be committed:
#   (use “git reset HEAD <file>…” to unstage)
#
#    modified:   README.rdoc
#
# Changes not staged for commit:
#   (use “git add <file>…” to update what will be committed)
#   (use “git checkout — <file>…” to discard changes in working directory)
#
#    modified:   Rakefile

4oo. Tree of git files

pravinmishra@ubuntu:~/workSpace/every_thing_with_git$ tree -a
.
├── app
│   ├── assets
│   │   ├── images
│   │   │   └── rails.png
│   │   ├── javascripts
│   │   │   ├── application.js
│   │   │   └── orders.js.coffee
│   │   └── stylesheets
│   │       ├── application.css
│   │       ├── orders.css.scss
│   │       └── scaffolds.css.scss
│   ├── controllers
│   │   ├── application_controller.rb
│   │   └── orders_controller.rb
│   ├── helpers
│   │   ├── application_helper.rb
│   │   └── orders_helper.rb
│   ├── mailers
│   │   └── .gitkeep
│   ├── models
│   │   ├── .gitkeep
│   │   └── order.rb
│   └── views
│       ├── layouts
│       │   └── application.html.erb
│       └── orders
│           ├── edit.html.erb
│           ├── _form.html.erb
│           ├── index.html.erb
│           ├── new.html.erb
│           └── show.html.erb
├── config
│   ├── application.rb
│   ├── boot.rb
│   ├── database.yml
│   ├── environment.rb
│   ├── environments
│   │   ├── development.rb
│   │   ├── production.rb
│   │   └── test.rb
│   ├── initializers
│   │   ├── backtrace_silencers.rb
│   │   ├── inflections.rb
│   │   ├── mime_types.rb
│   │   ├── secret_token.rb
│   │   ├── session_store.rb
│   │   └── wrap_parameters.rb
│   ├── locales
│   │   └── en.yml
│   └── routes.rb
├── config.ru
├── db
│   ├── migrate
│   │   └── 20120731003213_create_orders.rb
│   ├── schema.rb
│   └── seeds.rb
├── doc
│   └── README_FOR_APP
├── Gemfile
├── Gemfile.lock
├── .git
│   ├── branches
│   ├── COMMIT_EDITMSG
│   ├── COMMIT_EDITMSGtest
│   ├── COMMIT_EDITMSGtestt
│   ├── COMMIT_EDITMSGtesttM-A
│   ├── config
│   ├── description
│   ├── HEAD
│   ├── hooks
│   │   ├── applypatch-msg.sample
│   │   ├── commit-msg.sample
│   │   ├── post-update.sample
│   │   ├── pre-applypatch.sample
│   │   ├── pre-commit.sample
│   │   ├── prepare-commit-msg.sample
│   │   ├── pre-rebase.sample
│   │   └── update.sample
│   ├── index
│   ├── info
│   │   └── exclude
│   ├── logs
│   │   ├── HEAD
│   │   └── refs
│   │       ├── heads
│   │       │   ├── blue
│   │       │   ├── email
│   │       │   ├── master
│   │       │   └── rspec-test
│   │       └── remotes
│   │           └── origin
│   │               └── master
│   ├── objects
│   │   ├── 00
│   │   │   └── 7ce9c43328f559333b67ab5661248fd3555aff
│   │   ├── 01
│   │   │   └── a7a5fc116da111c0bc377b87972824ac5a5d5a
│   │   ├── 02
│   │   │   └── 5d1b1f1862d54aad0677bb80baec240fc27db7
│   │   ├── 05
│   │   │   ├── 188f08ed67cd28c1540da208992d57bc50f5d2
│   │   │   └── f4b2c6730253dd0533e426aad35d9551aa49bf
│   │   ├── 08
│   │   │   └── 5187fa58b1631e955f5d514d895a7721466797
│   │   ├── 0d
│   │   │   └── d897d9f57ced84d38e2776d21bf3fba6cb30d6
│   │   ├── 0f
│   │   │   └── bf4a10a9e4e258a83e6857411bc1a87ab5534e
│   │   ├── 12
│   │   │   └── e53b5cfb7713b7886a2e6de22b37be63cb1828
│   │   ├── 15
│   │   │   ├── 438849134f3078999b496a312773c88cecd84e
│   │   │   ├── 4705c6aa1c8ead8c99c7915373e3c44012057f
│   │   │   ├── 93355496d89e475ab4cd45808a7001dc6bd933
│   │   │   └── b8ed1348be35f46103e9a0cd10fec2b4919930
│   │   ├── 17
│   │   │   └── 9c14ca52c384fc27f42fa76ea982c4674b3c20
│   │   ├── 19
│   │   │   └── cb1c637acfd6f8ab180aaf1b0b45b610cbf006
│   │   ├── 1f
│   │   │   ├── 3bebad2659e088ac0c926c18511666b3c8b4b8
│   │   │   └── f053a7037e907af4a60cfdd34eca29da75f6f3
│   │   ├── 20
│   │   │   └── 4e9b656452b48c9dd9226255fdf17bd84d5ca1
│   │   ├── 21
│   │   │   └── 1748af0c417e6a03c6cb6f76d35e7d46d7d1f4
│   │   ├── 22
│   │   │   └── 68ce8216edd04b11b2e969997d799ed36bf90e
│   │   ├── 24
│   │   │   └── 20abe3038342909597705c910ffb8dfc6bd38b
│   │   ├── 27
│   │   │   └── abbf6392125b7c185f341d05b9369fde8ea5aa
│   │   ├── 28
│   │   │   └── c4a60cb62d6a5ef24ec8da1433d456fc5996e5
│   │   ├── 2b
│   │   │   └── 82d8b75e96d533432d9f11ee85462c1fd42393
│   │   ├── 2c
│   │   │   └── 56fa20dfed26d706d0e42e1fedcd310465f2d6
│   │   ├── 2d
│   │   │   ├── 06b8425bcb28592835ce1133f500e243770cb6
│   │   │   └── efd72e4d0a58b91b25f17f9d09315378b9d11d
│   │   ├── 30
│   │   │   └── 8bd499ed787a5661f7d537430c46884bad2a64
│   │   ├── 31
│   │   │   └── 92ec897bb6021141b0d304b724886d0907c0db
│   │   ├── 32
│   │   │   └── bbc36b8f5793223ef2c67308d344250fbdeb01
│   │   ├── 35
│   │   │   └── 37cfa635ef6d89fd8f5b51423ff364e79321c6
│   │   ├── 3b
│   │   │   └── 0428a94ef40b42809434e8b8fd289cd84b5b56
│   │   ├── 3c
│   │   │   └── 8f3fa4a33a630600099cce22c4bad1f420b89b
│   │   ├── 3f
│   │   │   ├── 5ddd8378f7b1bd43edf3bdbf6d8c923878f85c
│   │   │   ├── 91c121c8803e43a570061c7c43229602937458
│   │   │   └── ea27b91670e04c83a15269790a44b41b7d9ce1
│   │   ├── 42
│   │   │   ├── f6f6014f3d56aa9a43686c5de88c1860f9b715
│   │   │   └── fa3b2ead43317131e51b1e179c0eb58b319f82
│   │   ├── 43
│   │   │   └── d29f4f52246e7203a60c102c390c11ad55f474
│   │   ├── 44
│   │   │   ├── 3227fd481070889635a8205fb8ee06148fa209
│   │   │   ├── 89e58688ca642d8e0e9489f6896f49f9b89da6
│   │   │   └── 9b797391bd561d7aeb4adf870b6bddafe469b2
│   │   ├── 45
│   │   │   └── 774453e52bc437ff39123d471007b860095e86
│   │   ├── 46
│   │   │   └── 8d484a61f2d000ee5951262b9a1d51bf32a102
│   │   ├── 47
│   │   │   ├── c0f123aa7cd47e0f7169585a6d560aefabc65e
│   │   │   └── ddd6d409e52291d937d65a40ab88e7af3053f2
│   │   ├── 48
│   │   │   └── 6da35de91d3892e489f691c37bf25255addca3
│   │   ├── 49
│   │   │   ├── 30a6b713cd0c6f40160a427ef3f7581fcbbd3f
│   │   │   └── d4560b3981a89676c58e26550fded2ad5e9685
│   │   ├── 4a
│   │   │   ├── c1b3d98e3a170c44a846ddaf6d46721586d29c
│   │   │   └── ed04aba9a88a2cce4a3270fed3056e3ede6f43
│   │   ├── 4b
│   │   │   └── 66d04a4f062834cec2c55805291fed724b98f6
│   │   ├── 4e
│   │   │   ├── 10bf15eb422c2f87467cd41bc4875152918845
│   │   │   └── db1e857ee6c203463c7fa0387aae32496ec93d
│   │   ├── 50
│   │   │   └── 9ea6b2a89e29512b4fd0c92c1c4466dc18e8f8
│   │   ├── 52
│   │   │   ├── 0585c934bad43db8a390333c103c552a393f9e
│   │   │   └── dacae1997b7b0b90706a51b91860b114cc1a04
│   │   ├── 53
│   │   │   └── 091f8d943728655c2de5e283c5e2041f35d500
│   │   ├── 59
│   │   │   └── 385cdf379bd06a8d2326dcd4de6d5cd5d3f5b0
│   │   ├── 5a
│   │   │   └── 67a145b11f852d9e45e34afca9c5e5b03c2ea3
│   │   ├── 5b
│   │   │   └── 3cf596fc4c3779536f5b9c29cb49af36938fe5
│   │   ├── 5c
│   │   │   └── 302a4dd4b189d391fe0b0a59faacbc6aa62123
│   │   ├── 5d
│   │   │   └── 8d9be237b28d4ebdad9cec9510764ab88154e6
│   │   ├── 67
│   │   │   └── 0521830734291afbea54a6cad7bc1d5cc62e80
│   │   ├── 72
│   │   │   ├── a250e46f5ec97389f062760951692adb720e49
│   │   │   └── aca7e441e1855f8c7a7ac1f1cbe5d42cd1235b
│   │   ├── 75
│   │   │   └── 3d544d7891331263a1e4ca047cab572b839565
│   │   ├── 76
│   │   │   └── 1567942fc20b22ba68ce6b5f46652cf63c48c0
│   │   ├── 77
│   │   │   └── 3f006428ea5ea0ac1101ab7e1f5914eda247a8
│   │   ├── 7c
│   │   │   └── 36f2356ecd12c70a4bfcde0ff671e560daf460
│   │   ├── 7f
│   │   │   └── be8dcb97d0e801b6ec9fc4278d7c420a797cc5
│   │   ├── 83
│   │   │   ├── 660ab1878ba9adc6477ed910333e32bb6b46ce
│   │   │   └── 813df06fda0023b88014318c01f788ea17406f
│   │   ├── 84
│   │   │   └── cdcd11c41c66897ec8327615028742071ae1f8
│   │   ├── 85
│   │   │   └── a070328bff3bf5835f7b27389899a00b817102
│   │   ├── 88
│   │   │   └── bef2ca81958faed1a6f5d006d14f26a1242ead
│   │   ├── 8a
│   │   │   └── 4b162bdb9f2d82d0dc38316444af0cefa5164e
│   │   ├── 8b
│   │   │   └── f1192ffec252a4562218bdf299891a319b9cb9
│   │   ├── 90
│   │   │   └── 97d830e2c27e4b1dd291b1e3ee72149251cca1
│   │   ├── 93
│   │   │   └── 30726268264424cda78f32f874bae8f61c24f8
│   │   ├── 97
│   │   │   └── 939a10a5523838c7f3ca1a3dd6bfb5b3406328
│   │   ├── 99
│   │   │   ├── 9df20181e5571fb6a74259eead0899b7ad18a1
│   │   │   └── d71831621c0f06529c39b21105a8402080310b
│   │   ├── 9a
│   │   │   ├── 48320a5f1c025b6cc9819ab539a6d17fcbaf81
│   │   │   └── 6d84a35b2adc97e67f9bdcc8eb7f17f49b48d9
│   │   ├── 9b
│   │   │   └── 9bd01b00b30ab6ee52b3e86a16ce1cf844808d
│   │   ├── 9e
│   │   │   └── 2aeb8f9431726fb731bca2159a644e30e811fb
│   │   ├── 9f
│   │   │   └── 1580f4e69b030b59fceed046480856dd209df1
│   │   ├── ac
│   │   │   └── 2e8ba6a1b189557429b5ae2f59731e101728fb
│   │   ├── b0
│   │   │   ├── 7ade6c63bc0f43b5f33acda4822a4ff37361ea
│   │   │   └── f4f06fae59165f0f797b5e056d259726b3d455
│   │   ├── b4
│   │   │   └── 0d2b59d1e32e5056ba427b9b3fd0644630f683
│   │   ├── b5
│   │   │   └── 91a352dc8adfcbc781dfbcaed4d5489b3d0175
│   │   ├── bd
│   │   │   └── 5ae3fecb4feaf0f865888edc9759d5c3d36232
│   │   ├── c2
│   │   │   └── e811817ee56b7c4f80a98a0e29215af57c2a3a
│   │   ├── c4
│   │   │   └── f14ff630a65048705dd1848a773aec6e98e321
│   │   ├── cb
│   │   │   └── deac2798cb5fde79016e7ee7961331aa4f7c7b
│   │   ├── ce
│   │   │   └── 506525fe3467ef70cf1485a2793300622534d6
│   │   ├── d2
│   │   │   └── c3f035da1c14b4efead05e6f9db416a290fde2
│   │   ├── d5
│   │   │   ├── 64d0bc3dd917926892c55e3706cc116d5b165e
│   │   │   └── edc04e65f555e3ba4dcdaad39dc352e75b575e
│   │   ├── d9
│   │   │   └── 2e427847e01b1a6f07b19e25e7b0668efaec69
│   │   ├── dd
│   │   │   ├── 05fa5b40902c631ed1a82d379e7054f88e59ad
│   │   │   └── fbd7c203be41f36d2ac1404857500f1f865b2e
│   │   ├── de
│   │   │   └── 6be7945c6a59798eb0ace177df38b05e98c2f0
│   │   ├── e1
│   │   │   └── 06f5eb4da1651e7a2e3d01d65eab298f9b38e4
│   │   ├── e3
│   │   │   └── ed01cb6b9dc73ab83658f50f17770af0b6db2a
│   │   ├── e6
│   │   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391
│   │   ├── e8
│   │   │   └── 065d9505d7ec6f727021c827de18a0a95737de
│   │   ├── ea
│   │   │   └── 3ba0e03a6b78f2a812f1dccbf99ea2a1ddabbc
│   │   ├── eb
│   │   │   └── 3489a986bd8af22f03119e8989e9d10a4999d4
│   │   ├── ed
│   │   │   ├── 7931e3f168c9831579326b56de3f3c68f3b5da
│   │   │   └── ae7ef0915f4b60dd173a268a92ce766009152c
│   │   ├── f3
│   │   │   └── 648a0dbc9f021131677c88383f1cc9b15ea22e
│   │   ├── f5
│   │   │   ├── 346619e66f9e59ed6141ba46ec7bd899d82de0
│   │   │   └── 491c2323e75b9df95eb3c8f5a1cd064bc35a8b
│   │   ├── f7
│   │   │   ├── 6cb1d43f2a6ea96e48e95cf70d3a8704dd5072
│   │   │   └── bd8f6a14841f95d2840ab870dddb1132c730b2
│   │   ├── f8
│   │   │   └── da2cffd4de029d658fe2f7b9ec88f28dc34a9a
│   │   ├── fc
│   │   │   └── 6ef9282895a78dafdb3ebe9a982db6a9f1e0a0
│   │   ├── fd
│   │   │   └── e0ce2e205f9f0f055727dc7b6c5df08e362b6a
│   │   ├── fe
│   │   │   └── 41f5cc24d667635c46a533fd09bf7bb514e032
│   │   ├── info
│   │   └── pack
│   ├── ORIG_HEAD
│   └── refs
│       ├── heads
│       │   ├── blue
│       │   ├── email
│       │   ├── master
│       │   └── rspec-test
│       ├── remotes
│       │   └── origin
│       │       └── master
│       └── tags
├── .gitignore
├── lib
│   ├── assets
│   │   └── .gitkeep
│   └── tasks
│       └── .gitkeep
├── log
│   ├── development.log
│   └── .gitkeep
├── public
│   ├── 404.html
│   ├── 422.html
│   ├── 500.html
│   ├── favicon.ico
│   └── robots.txt
├── Rakefile
├── README.rdoc
├── script
│   └── rails
├── test
│   ├── fixtures
│   │   ├── .gitkeep
│   │   └── orders.yml
│   ├── functional
│   │   ├── .gitkeep
│   │   └── orders_controller_test.rb
│   ├── integration
│   │   └── .gitkeep
│   ├── performance
│   │   └── browsing_test.rb
│   ├── test_helper.rb
│   └── unit
│       ├── .gitkeep
│       ├── helpers
│       │   └── orders_helper_test.rb
│       └── order_test.rb
├── tmp
│   ├── cache
│   │   ├── assets
│   │   │   ├── C58
│   │   │   │   └── E30
│   │   │   │       └── sprockets%2F4e829185f1504944b41c494529b66bb4
│   │   │   ├── CB5
│   │   │   │   └── 9E0
│   │   │   │       └── sprockets%2Fe459168835a5f27b832ace20874f7c10
│   │   │   ├── CC2
│   │   │   │   └── 5A0
│   │   │   │       └── sprockets%2F2630585056a1db4f59b004c2aa5122cd
│   │   │   ├── CD7
│   │   │   │   └── 6F0
│   │   │   │       └── sprockets%2Fbd3936370d0f952ada5774e2230046ed
│   │   │   ├── CD8
│   │   │   │   └── 370
│   │   │   │       └── sprockets%2F357970feca3ac29060c1e3861e2c0953
│   │   │   ├── CF0
│   │   │   │   └── DA0
│   │   │   │       └── sprockets%2Fd7d5b37686831d37c4dd75e645f5e016
│   │   │   ├── CF4
│   │   │   │   └── CE0
│   │   │   │       └── sprockets%2Fda5971a6f6cc7e9923f28850c46625b8
│   │   │   ├── D1F
│   │   │   │   └── D30
│   │   │   │       └── sprockets%2F6c9f4608bd916f573fafb413927d4d09
│   │   │   ├── D20
│   │   │   │   └── BA0
│   │   │   │       └── sprockets%2Fe8d306af79db99713a3334ea95957d2c
│   │   │   ├── D32
│   │   │   │   └── A10
│   │   │   │       └── sprockets%2F13fe41fee1fe35b49d145bcc06610705
│   │   │   ├── D33
│   │   │   │   └── E20
│   │   │   │       └── sprockets%2F25e6a0c3cf070477edaae503564f426c
│   │   │   ├── D4E
│   │   │   │   └── 1B0
│   │   │   │       └── sprockets%2Ff7cbd26ba1d28d48de824f0e94586655
│   │   │   ├── D5A
│   │   │   │   └── EA0
│   │   │   │       └── sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6
│   │   │   ├── D7E
│   │   │   │   └── 510
│   │   │   │       └── sprockets%2Fe5289c1e989b8dd6656cd939e0ac0ac0
│   │   │   ├── D82
│   │   │   │   └── 350
│   │   │   │       └── sprockets%2F4cfa19f9bca26dc87fd9550127f4759e
│   │   │   ├── DDC
│   │   │   │   └── 400
│   │   │   │       └── sprockets%2Fcffd775d018f68ce5dba1ee0d951a994
│   │   │   ├── DED
│   │   │   │   └── F70
│   │   │   │       └── sprockets%2F7ed83d0c16cbc2b202b4c65baeec647c
│   │   │   ├── E04
│   │   │   │   └── 890
│   │   │   │       └── sprockets%2F2f5173deea6c795b8fdde723bb4b63af
│   │   │   ├── E0F
│   │   │   │   └── F70
│   │   │   │       └── sprockets%2F96eea36d34f8fef13ff7a1d0576d8eae
│   │   │   ├── E19
│   │   │   │   └── 2A0
│   │   │   │       └── sprockets%2F10fcfbe6ebae11a40c8eac41939a1b9a
│   │   │   └── E25
│   │   │       └── 4C0
│   │   │           └── sprockets%2Fde2fd9fd11c04a582cdbbe3d84a35ae6
│   │   └── sass
│   │       └── 7d2ae8fecd82f6692540c213575bf838322da99d
│   │           ├── orders.css.scssc
│   │           └── scaffolds.css.scssc
│   ├── pids
│   │   └── server.pid
│   ├── sessions
│   └── sockets
└── vendor
├── assets
│   ├── javascripts
│   │   └── .gitkeep
│   └── stylesheets
│       └── .gitkeep
└── plugins
└── .gitkeep

200 directories, 242 files

logger


What is logger?

  • Rails makes use of ruby’s standard logger, Log4r, or another logger that provides a similar interface can also be substituted if you wish.
  • A logger object is made available to each of ActiveRecord, ActiveController and ActiveMailer.

How to write logger?

  • logger.info "Starting process fubar..."

Log level?

  • IThe available log levels are: :debug, :info, :warn, :error, :fatal. The ruby Logger class normally also accepts :any, but that doesn’t seem to work with rails.
  • config.log_level = :debug

Log path?

  • The log file path is relative to the RAILS_ROOT directory. Make sure that the file exists and has permissions that allow writing for the user that rails will run under.
  • config.log_path = 'log/debug.log'

Initialize logger in ruby app?

  • ActiveRecord::Base.logger = Logger.new(STDERR)
  • ActiveRecord::Base.logger = Logger.new(File.open(‘log/database.log’, ‘a’))

Example?

begin
  RAILS_DEFAULT_LOGGER = Logger.new(“#{RAILS_ROOT}/log/#{RAILS_ENV}.log”)
rescue StandardError
  RAILS_DEFAULT_LOGGER = Logger.new(STDERR)
  RAILS_DEFAULT_LOGGER.level = Logger::WARN
  RAILS_DEFAULT_LOGGER.warn(
    “Rails Error: Unable to access log file. Please ensure that log/#{RAILS_ENV}.log exists and 
is chmod 0666. " +
    "The log level has been raised to WARN and the output directed to STDERR until the problem 
is fixed.”
  )
end

Q Is it possible to display the logs in the console rather than using the “debug.log” file?
-cd /railsapp/log
-tail -f development.log









































 

 

Setting Up Your Application to Use Bundler


Bundler makes sure that Ruby can find all of the gems in the Gemfile (and all of their dependencies).

For another kind of application (such as a Sinatra application/Ruby app), you will need to set up bundler before trying to require any gems. At the top of the first file that your application loads , put the following code:

require "rubygems"
require "bundler/setup"

This will automatically discover your Gemfile, and make all of the gems in your Gemfile available to Ruby (in technical terms, it puts the gems “on the load path”). You can think of it as an adding some extra powers to require "rubygems".

Now that your code is available to Ruby, you can require the gems that you need. For instance, you can require "nokogiri". If you have a lot of dependencies, you might want to say “require all of the gems in my Gemfile“. To do this, put the following code immediately following require "bundler/setup":
Bundler.require(:default)

 

Using Bundler with Rails 2.3


1. Insert the following code in config/boot.rb, right above the line `Rails.boot!`

class Rails::Boot
  def run
    load_initializer

    Rails::Initializer.class_eval do
      def load_gems
        @bundler_loaded ||= Bundler.require :default, Rails.env
      end
    end

    Rails::Initializer.run(:set_load_path)
  end
end

2.Create a new file, config/preinitializer.rb, and insert the following.

begin
  require "rubygems"
  require "bundler"
rescue LoadError
  raise "Could not load the bundler gem. Install it with `gem install bundler`."
end

if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
  raise RuntimeError, "Your bundler version is too old for Rails 2.3." +
   "Run `gem install bundler` to upgrade."
end

begin
  # Set up load paths for all bundled gems
  ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
  Bundler.setup
rescue Bundler::GemNotFound
  raise RuntimeError, "Bundler couldn't find some gems." +
    "Did you run `bundle install`?"
end
That's it :)