rscratch 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/MIT-LICENSE +20 -0
- data/README.md +99 -0
- data/Rakefile +40 -0
- data/app/assets/javascripts/rscratch/Chart.min.js +11 -0
- data/app/assets/javascripts/rscratch/application.js +128 -0
- data/app/assets/javascripts/rscratch/dashboard.js +90 -0
- data/app/assets/javascripts/rscratch/exceptions.js +97 -0
- data/app/assets/javascripts/rscratch/templates/exception_overview.jst.ejs +57 -0
- data/app/assets/javascripts/rscratch/templates/loader.jst.ejs +65 -0
- data/app/assets/stylesheets/rscratch/application.css +13 -0
- data/app/assets/stylesheets/rscratch/style.css +101 -0
- data/app/controllers/rscratch/application_controller.rb +12 -0
- data/app/controllers/rscratch/dashboard_controller.rb +13 -0
- data/app/controllers/rscratch/exceptions_controller.rb +23 -0
- data/app/helpers/rscratch/application_helper.rb +4 -0
- data/app/helpers/rscratch/dashboard_helper.rb +4 -0
- data/app/helpers/rscratch/exceptions_helper.rb +4 -0
- data/app/models/rscratch/exception.rb +68 -0
- data/app/models/rscratch/exception_log.rb +49 -0
- data/app/views/layouts/rscratch/application.html.haml +35 -0
- data/app/views/rscratch/dashboard/index.html.haml +12 -0
- data/app/views/rscratch/exceptions/_exception_smartlist.html.haml +21 -0
- data/app/views/rscratch/exceptions/index.html.haml +59 -0
- data/app/views/rscratch/exceptions/index.js.erb +3 -0
- data/app/views/rscratch/exceptions/show.json.jbuilder +13 -0
- data/app/views/smart_listing/_action_custom.html.erb +10 -0
- data/app/views/smart_listing/_action_delete.html.erb +12 -0
- data/app/views/smart_listing/_action_edit.html.erb +11 -0
- data/app/views/smart_listing/_action_show.html.erb +11 -0
- data/app/views/smart_listing/_item_new.html.erb +30 -0
- data/app/views/smart_listing/_pagination_per_page_link.html.erb +12 -0
- data/app/views/smart_listing/_pagination_per_page_links.html.erb +19 -0
- data/app/views/smart_listing/_sortable.html.erb +21 -0
- data/config/routes.rb +8 -0
- data/db/migrate/20160123064059_create_rscratch_exceptions.rb +15 -0
- data/db/migrate/20160123064828_create_rscratch_exception_logs.rb +17 -0
- data/lib/generators/rscratch/install/install_generator.rb +27 -0
- data/lib/generators/rscratch/install/templates/initializer.rb.erb +7 -0
- data/lib/generators/rscratch/install/templates/migration.rb +40 -0
- data/lib/rscratch.rb +11 -0
- data/lib/rscratch/configuration.rb +7 -0
- data/lib/rscratch/engine.rb +10 -0
- data/lib/rscratch/version.rb +3 -0
- data/lib/tasks/rscratch_tasks.rake +4 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/fixtures/rscratch/exception_logs.yml +23 -0
- data/test/fixtures/rscratch/exceptions.yml +19 -0
- data/test/functional/rscratch/dashboard_controller_test.rb +11 -0
- data/test/functional/rscratch/exceptions_controller_test.rb +11 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/rscratch_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- data/test/unit/helpers/rscratch/dashboard_helper_test.rb +6 -0
- data/test/unit/helpers/rscratch/exceptions_helper_test.rb +6 -0
- data/test/unit/rscratch/exception_log_test.rb +9 -0
- data/test/unit/rscratch/exception_test.rb +9 -0
- metadata +235 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
.teal.darken-3.col.s12.12
|
2
|
+
.section.p20
|
3
|
+
%h5.teal-text.text-lighten-5.font-16 Latest Scratches
|
4
|
+
%h6.teal-text.text-lighten-3.font-12 Bugs and Exceptions in your application
|
5
|
+
%div{:style=>"min-height:250px;"}
|
6
|
+
%canvas#exception-line-canvas{:height => "80"}
|
7
|
+
.clearfix
|
8
|
+
|
9
|
+
:javascript
|
10
|
+
$(document).ready(function() {
|
11
|
+
load_dashboard_UI_components();
|
12
|
+
});
|
@@ -0,0 +1,21 @@
|
|
1
|
+
- unless smart_listing.empty?
|
2
|
+
%ul.collection.margin-t-0
|
3
|
+
- smart_listing.collection.each do |object|
|
4
|
+
%li.collection-item.avatar.min-height-70.waves-effect.width-100.exception-item{:class=>"excp-item-#{object.id}","data-exception-id"=>object.id, "data-exception-message"=>object.message, "data-exception-date"=>object.updated_at.strftime("%d-%m-%Y, %I:%M %p"), "data-exception-total-count"=>object.total_occurance_count, "data-exception-new-count"=>object.new_occurance_count, "data-exception-controller"=>object.controller, "data-exception-action"=>object.action, "data-exception-raw"=>object.exception}
|
5
|
+
%i.margin-t-5.material-icons.circle.red.font-24 bug_report
|
6
|
+
%span.secondary-content.label=object.total_occurance_count
|
7
|
+
%h6.grey-text.text-darken-4.margin-t-0.truncate=object.message
|
8
|
+
%h6.grey-text.text-darken-3.margin-t-0.truncate.font-11=object.exception
|
9
|
+
%h6.margin-0
|
10
|
+
%span.label.orange=object.app_environment
|
11
|
+
%span.grey-text="#{object.controller}##{object.action}"
|
12
|
+
%span.grey-text.font-11.right="#{time_ago_in_words(object.updated_at)} ago"
|
13
|
+
%center
|
14
|
+
= smart_listing.paginate
|
15
|
+
= smart_listing.pagination_per_page_links
|
16
|
+
%br
|
17
|
+
%br
|
18
|
+
%br
|
19
|
+
%br
|
20
|
+
- else
|
21
|
+
%p.warning No records!
|
@@ -0,0 +1,59 @@
|
|
1
|
+
:javascript
|
2
|
+
$(document).ready(function(){
|
3
|
+
$('ul.tabs').tabs();
|
4
|
+
});
|
5
|
+
|
6
|
+
.row
|
7
|
+
.col.s4.p0.fixed-sidebar.z-depth-1
|
8
|
+
%ul.tabs.light-blue
|
9
|
+
%li.tab.col.s6
|
10
|
+
%a.white-text.waves-effect.waves-light.active{:href => "#new-ex"} New
|
11
|
+
%li.tab.col.s6
|
12
|
+
%a.white-text.waves-effect.waves-light{:href => "#resolved-ex"} Resolved
|
13
|
+
#new-ex.p0
|
14
|
+
=# smart_listing_controls_for(:exceptions, {class: "form-inline text-right"}) do
|
15
|
+
=# text_field_tag :filter, '', class: "search form-control", placeholder: "Search...", autocomplete: :off
|
16
|
+
= smart_listing_render :exceptions
|
17
|
+
#resolved-ex.p0
|
18
|
+
= smart_listing_render :resolved_exceptions
|
19
|
+
|
20
|
+
.col.s8.p0{:style=>"float:right"}
|
21
|
+
.card#log-page-header.exception-info.margin-0
|
22
|
+
.card-image.waves-effect.waves-block.waves-light.grey
|
23
|
+
%canvas#log-count-canvas{:height => "89","chart-legend" => "true"}
|
24
|
+
.card-content
|
25
|
+
.row.margin-0
|
26
|
+
.col.s8
|
27
|
+
%h6.card-title.font-18.grey-text.text-darken-4.exception-message
|
28
|
+
%p.medium-small.grey-text
|
29
|
+
%h6.margin-t-0.grey-text.exception-raw
|
30
|
+
%h6.margin-t-0.grey-text.ex-controller
|
31
|
+
%h6.margin-t-0.grey-text.exception-date
|
32
|
+
.col.s2.center-align
|
33
|
+
%h4.card-title.grey-text.text-darken-4.exception-total-count
|
34
|
+
%p.medium-small.grey-text Total Occurrences
|
35
|
+
.col.s2.center-align
|
36
|
+
%h4.card-title.grey-text.text-darken-4.exception-new-count
|
37
|
+
%p.medium-small.grey-text Since Last Resolved
|
38
|
+
.col.s1
|
39
|
+
.col.s12.exception-info
|
40
|
+
.card
|
41
|
+
|
42
|
+
%ul.tabs.tab-profile.z-depth-1.red
|
43
|
+
%li.tab
|
44
|
+
%a.white-text.waves-effect.waves-light.active{:href => "#overview"}
|
45
|
+
Overview
|
46
|
+
%li.tab
|
47
|
+
%a.white-text.waves-effect.waves-light{:href => "#backtrace"}
|
48
|
+
Backtrace
|
49
|
+
%li.tab
|
50
|
+
%a.white-text.waves-effect.waves-light{:href => "#params"}
|
51
|
+
Parameters
|
52
|
+
.indicator{:style => "right: 541px; left: 0px;"}
|
53
|
+
|
54
|
+
#overview.p20.progress-loader
|
55
|
+
#backtrace.p5
|
56
|
+
%pre.language-markup.ex-backtrace.font-10
|
57
|
+
#params.p20
|
58
|
+
%pre.language-markup.ex-params
|
59
|
+
%h5.grey-text.font-weight-300.center-align.text-lighten-1.no-exception{:style=>"margin-top:200px;"} No exception selected
|
@@ -0,0 +1,13 @@
|
|
1
|
+
json.status @error.present? ? "error" : "ok"
|
2
|
+
json.message @error.present? ? @error.message : "Exception data loaded."
|
3
|
+
if @error.present?
|
4
|
+
json.data Array.new
|
5
|
+
else
|
6
|
+
json.data do
|
7
|
+
json.extract! @excp, :action, :app_environment, :controller, :exception, :message, :new_occurance_count, :total_occurance_count, :created_at, :updated_at
|
8
|
+
json.log do
|
9
|
+
json.extract! @log.first, :backtrace, :client_ip, :description, :exception_id, :parameters, :request_method, :request_url, :status, :user_agent, :created_at, :updated_at
|
10
|
+
end
|
11
|
+
json.log_summary @historical_data
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%#
|
2
|
+
Delete action.
|
3
|
+
|
4
|
+
Available local variables:
|
5
|
+
action_if: false if action is disabled
|
6
|
+
url: destroy url
|
7
|
+
icon: icon css classes
|
8
|
+
confirmation: confrimation text
|
9
|
+
title
|
10
|
+
-%>
|
11
|
+
|
12
|
+
<%= link_to_if(action_if, content_tag(:i, "", :class => icon), url, :remote => true, :class => "destroy", :method => :delete, :title => title || t("smart_listing.actions.destroy"), :data => {:confirmation => confirmation || t("smart_listing.msgs.destroy_confirmation")} ) %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%#
|
2
|
+
Edit action.
|
3
|
+
|
4
|
+
Available local variables:
|
5
|
+
action_if: false if action is disabled
|
6
|
+
url: edit url
|
7
|
+
icon: icon css classes
|
8
|
+
title
|
9
|
+
-%>
|
10
|
+
|
11
|
+
<%= link_to_if(action_if, content_tag(:i, '', :class => icon), url, :remote => true, :class => "edit", :title => title || t("smart_listing.actions.edit") ) %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%#
|
2
|
+
Show action.
|
3
|
+
|
4
|
+
Available local variables:
|
5
|
+
action_if: false if action is disabled
|
6
|
+
url: show url
|
7
|
+
icon: icon clss classes
|
8
|
+
title
|
9
|
+
-%>
|
10
|
+
|
11
|
+
<%= link_to_if(action_if, content_tag(:i, '', :class => icon), url, :class => "show", :title => title || t("smart_listing.actions.show") ) %>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<%#
|
2
|
+
New list item element (contains new item placeholder and add button).
|
3
|
+
|
4
|
+
Available local variables:
|
5
|
+
placeholder_classes: classes for the main container
|
6
|
+
new_item_action_classes: new item action classes
|
7
|
+
colspan
|
8
|
+
no_items_classes: no items container classes
|
9
|
+
no_items_text: no items text displayed inside container
|
10
|
+
new_item_button_url: argument to link_to (new item button)
|
11
|
+
new_item_button_classes
|
12
|
+
new_item_button_text
|
13
|
+
new_item_autoshow automatically show new item placeholder
|
14
|
+
new_item_content new item placeholder content (usually some form)
|
15
|
+
-%>
|
16
|
+
|
17
|
+
<%= content_tag(:tr, '', :class => placeholder_classes + %w{info}, :data => {smart_listing_config.data_attributes(:autoshow) => new_item_autoshow}) do %>
|
18
|
+
<%= new_item_content %>
|
19
|
+
<% end %>
|
20
|
+
<%= content_tag(:tr, :class => new_item_action_classes + %w{info}) do %>
|
21
|
+
<%= content_tag(:td, :colspan => colspan) do %>
|
22
|
+
<%= content_tag(:p, :class => no_items_classes + %w{pull-left}) do %>
|
23
|
+
<%= no_items_text %>
|
24
|
+
<% end %>
|
25
|
+
<%= link_to(new_item_button_url, :remote => true, :class => new_item_button_classes + %w{btn pull-right}) do %>
|
26
|
+
<%= content_tag(:i, '', :class => smart_listing_config.classes(:icon_new)) %>
|
27
|
+
<%= new_item_button_text %>
|
28
|
+
<% end %>
|
29
|
+
<% end %>
|
30
|
+
<% end %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%#
|
2
|
+
Pagination single per-page link.
|
3
|
+
|
4
|
+
Available local variables:
|
5
|
+
page: page number
|
6
|
+
url: page url (if page is not selected)
|
7
|
+
smart_listing: current SmartListing instance
|
8
|
+
builder: current builder instance
|
9
|
+
-%>
|
10
|
+
|
11
|
+
<% name = page == 0 ? t('views.pagination.unlimited') : page %>
|
12
|
+
<%= url ? link_to(name, url, :remote => smart_listing.remote?) : content_tag(:span, name) %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<%#
|
2
|
+
Pagination per-page links.
|
3
|
+
|
4
|
+
Available local variables:
|
5
|
+
container_classes: classes for the main container
|
6
|
+
per_page_sizes: array of available per-page sizes
|
7
|
+
smart_listing: current SmartListing instance
|
8
|
+
builder: current builder instance
|
9
|
+
-%>
|
10
|
+
|
11
|
+
<%= content_tag(:div, :class => container_classes ) do %>
|
12
|
+
<% if smart_listing.options[:paginate] && (smart_listing.count > smart_listing.page_sizes.first) %>
|
13
|
+
<%= t('views.pagination.per_page') %>
|
14
|
+
<% per_page_sizes.each do |p| %><%= builder.pagination_per_page_link p %><% break if p >= smart_listing.count %><% end %>
|
15
|
+
|
|
16
|
+
<% end %>
|
17
|
+
<%= t('views.pagination.total') %>
|
18
|
+
<%= content_tag(:span, smart_listing.count, :class => "count") %>
|
19
|
+
<% end %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<%#
|
2
|
+
Sortable attribute listing header.
|
3
|
+
|
4
|
+
Available local variables:
|
5
|
+
container_classes: classes for the main container
|
6
|
+
url: sortable link url
|
7
|
+
attribute: current attribute name
|
8
|
+
title: current attribute title
|
9
|
+
order: defines column sort order
|
10
|
+
smart_listing: current SmartListing instance
|
11
|
+
builder: current builder instance
|
12
|
+
-%>
|
13
|
+
|
14
|
+
<%= link_to url, :class => container_classes, :data => {:attr => attribute}, :remote => true do %>
|
15
|
+
<%= title %>
|
16
|
+
<% if order %>
|
17
|
+
<span class="<%= order == "asc" ? smart_listing_config.classes(:icon_sort_up) : smart_listing_config.classes(:icon_sort_down) %>"></span>
|
18
|
+
<% else %>
|
19
|
+
<span class="<%= smart_listing_config.classes(:icon_sort_none) %>"></span>
|
20
|
+
<% end %>
|
21
|
+
<% end %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateRscratchExceptions < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :rscratch_exceptions do |t|
|
4
|
+
t.text :exception
|
5
|
+
t.text :message
|
6
|
+
t.string :controller
|
7
|
+
t.string :action
|
8
|
+
t.string :app_environment
|
9
|
+
t.integer :total_occurance_count
|
10
|
+
t.integer :new_occurance_count
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateRscratchExceptionLogs < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :rscratch_exception_logs do |t|
|
4
|
+
t.integer :exception_id
|
5
|
+
t.text :description
|
6
|
+
t.text :backtrace
|
7
|
+
t.text :request_url
|
8
|
+
t.string :request_method
|
9
|
+
t.text :parameters
|
10
|
+
t.string :user_agent
|
11
|
+
t.string :client_ip
|
12
|
+
t.string :status
|
13
|
+
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Rscratch
|
2
|
+
class InstallGenerator < ::Rails::Generators::Base
|
3
|
+
source_root File.expand_path("../templates", __FILE__)
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
def self.next_migration_number(path)
|
7
|
+
unless @prev_migration_nr
|
8
|
+
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
9
|
+
else
|
10
|
+
@prev_migration_nr += 1
|
11
|
+
end
|
12
|
+
@prev_migration_nr.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def copy_migrations
|
16
|
+
migration_template "migration.rb", "db/migrate/rscratch_schema_migration.rb"
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_initializer
|
20
|
+
template 'initializer.rb.erb', 'config/initializers/rscratch.rb'
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_route
|
24
|
+
route("mount Rscratch::Engine => '/rscratch'")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class RscratchSchemaMigration < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
# Exception table
|
4
|
+
create_table :rscratch_exceptions do |t|
|
5
|
+
t.text :exception
|
6
|
+
t.text :message
|
7
|
+
t.string :controller
|
8
|
+
t.string :action
|
9
|
+
t.string :app_environment
|
10
|
+
t.integer :total_occurance_count
|
11
|
+
t.integer :new_occurance_count
|
12
|
+
t.string :status
|
13
|
+
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
|
17
|
+
# Exception log table
|
18
|
+
create_table :rscratch_exception_logs do |t|
|
19
|
+
t.integer :exception_id
|
20
|
+
t.text :description
|
21
|
+
t.text :backtrace
|
22
|
+
t.text :request_url
|
23
|
+
t.string :request_method
|
24
|
+
t.text :parameters
|
25
|
+
t.string :user_agent
|
26
|
+
t.string :client_ip
|
27
|
+
t.string :status
|
28
|
+
|
29
|
+
t.timestamps
|
30
|
+
end
|
31
|
+
|
32
|
+
# Config table
|
33
|
+
create_table :rscratch_configurations do |tc|
|
34
|
+
tc.string :config_key
|
35
|
+
tc.string :config_value
|
36
|
+
|
37
|
+
tc.timestamps
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/rscratch.rb
ADDED
@@ -0,0 +1,261 @@
|
|
1
|
+
== Welcome to Rails
|
2
|
+
|
3
|
+
Rails is a web-application framework that includes everything needed to create
|
4
|
+
database-backed web applications according to the Model-View-Control pattern.
|
5
|
+
|
6
|
+
This pattern splits the view (also called the presentation) into "dumb"
|
7
|
+
templates that are primarily responsible for inserting pre-built data in between
|
8
|
+
HTML tags. The model contains the "smart" domain objects (such as Account,
|
9
|
+
Product, Person, Post) that holds all the business logic and knows how to
|
10
|
+
persist themselves to a database. The controller handles the incoming requests
|
11
|
+
(such as Save New Account, Update Product, Show Post) by manipulating the model
|
12
|
+
and directing data to the view.
|
13
|
+
|
14
|
+
In Rails, the model is handled by what's called an object-relational mapping
|
15
|
+
layer entitled Active Record. This layer allows you to present the data from
|
16
|
+
database rows as objects and embellish these data objects with business logic
|
17
|
+
methods. You can read more about Active Record in
|
18
|
+
link:files/vendor/rails/activerecord/README.html.
|
19
|
+
|
20
|
+
The controller and view are handled by the Action Pack, which handles both
|
21
|
+
layers by its two parts: Action View and Action Controller. These two layers
|
22
|
+
are bundled in a single package due to their heavy interdependence. This is
|
23
|
+
unlike the relationship between the Active Record and Action Pack that is much
|
24
|
+
more separate. Each of these packages can be used independently outside of
|
25
|
+
Rails. You can read more about Action Pack in
|
26
|
+
link:files/vendor/rails/actionpack/README.html.
|
27
|
+
|
28
|
+
|
29
|
+
== Getting Started
|
30
|
+
|
31
|
+
1. At the command prompt, create a new Rails application:
|
32
|
+
<tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
|
33
|
+
|
34
|
+
2. Change directory to <tt>myapp</tt> and start the web server:
|
35
|
+
<tt>cd myapp; rails server</tt> (run with --help for options)
|
36
|
+
|
37
|
+
3. Go to http://localhost:3000/ and you'll see:
|
38
|
+
"Welcome aboard: You're riding Ruby on Rails!"
|
39
|
+
|
40
|
+
4. Follow the guidelines to start developing your application. You can find
|
41
|
+
the following resources handy:
|
42
|
+
|
43
|
+
* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
|
44
|
+
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
|
45
|
+
|
46
|
+
|
47
|
+
== Debugging Rails
|
48
|
+
|
49
|
+
Sometimes your application goes wrong. Fortunately there are a lot of tools that
|
50
|
+
will help you debug it and get it back on the rails.
|
51
|
+
|
52
|
+
First area to check is the application log files. Have "tail -f" commands
|
53
|
+
running on the server.log and development.log. Rails will automatically display
|
54
|
+
debugging and runtime information to these files. Debugging info will also be
|
55
|
+
shown in the browser on requests from 127.0.0.1.
|
56
|
+
|
57
|
+
You can also log your own messages directly into the log file from your code
|
58
|
+
using the Ruby logger class from inside your controllers. Example:
|
59
|
+
|
60
|
+
class WeblogController < ActionController::Base
|
61
|
+
def destroy
|
62
|
+
@weblog = Weblog.find(params[:id])
|
63
|
+
@weblog.destroy
|
64
|
+
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
The result will be a message in your log file along the lines of:
|
69
|
+
|
70
|
+
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
|
71
|
+
|
72
|
+
More information on how to use the logger is at http://www.ruby-doc.org/core/
|
73
|
+
|
74
|
+
Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
|
75
|
+
several books available online as well:
|
76
|
+
|
77
|
+
* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
|
78
|
+
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
|
79
|
+
|
80
|
+
These two books will bring you up to speed on the Ruby language and also on
|
81
|
+
programming in general.
|
82
|
+
|
83
|
+
|
84
|
+
== Debugger
|
85
|
+
|
86
|
+
Debugger support is available through the debugger command when you start your
|
87
|
+
Mongrel or WEBrick server with --debugger. This means that you can break out of
|
88
|
+
execution at any point in the code, investigate and change the model, and then,
|
89
|
+
resume execution! You need to install ruby-debug to run the server in debugging
|
90
|
+
mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
|
91
|
+
|
92
|
+
class WeblogController < ActionController::Base
|
93
|
+
def index
|
94
|
+
@posts = Post.all
|
95
|
+
debugger
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
So the controller will accept the action, run the first line, then present you
|
100
|
+
with a IRB prompt in the server window. Here you can do things like:
|
101
|
+
|
102
|
+
>> @posts.inspect
|
103
|
+
=> "[#<Post:0x14a6be8
|
104
|
+
@attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
|
105
|
+
#<Post:0x14a6620
|
106
|
+
@attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
|
107
|
+
>> @posts.first.title = "hello from a debugger"
|
108
|
+
=> "hello from a debugger"
|
109
|
+
|
110
|
+
...and even better, you can examine how your runtime objects actually work:
|
111
|
+
|
112
|
+
>> f = @posts.first
|
113
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
114
|
+
>> f.
|
115
|
+
Display all 152 possibilities? (y or n)
|
116
|
+
|
117
|
+
Finally, when you're ready to resume execution, you can enter "cont".
|
118
|
+
|
119
|
+
|
120
|
+
== Console
|
121
|
+
|
122
|
+
The console is a Ruby shell, which allows you to interact with your
|
123
|
+
application's domain model. Here you'll have all parts of the application
|
124
|
+
configured, just like it is when the application is running. You can inspect
|
125
|
+
domain models, change values, and save to the database. Starting the script
|
126
|
+
without arguments will launch it in the development environment.
|
127
|
+
|
128
|
+
To start the console, run <tt>rails console</tt> from the application
|
129
|
+
directory.
|
130
|
+
|
131
|
+
Options:
|
132
|
+
|
133
|
+
* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
|
134
|
+
made to the database.
|
135
|
+
* Passing an environment name as an argument will load the corresponding
|
136
|
+
environment. Example: <tt>rails console production</tt>.
|
137
|
+
|
138
|
+
To reload your controllers and models after launching the console run
|
139
|
+
<tt>reload!</tt>
|
140
|
+
|
141
|
+
More information about irb can be found at:
|
142
|
+
link:http://www.rubycentral.org/pickaxe/irb.html
|
143
|
+
|
144
|
+
|
145
|
+
== dbconsole
|
146
|
+
|
147
|
+
You can go to the command line of your database directly through <tt>rails
|
148
|
+
dbconsole</tt>. You would be connected to the database with the credentials
|
149
|
+
defined in database.yml. Starting the script without arguments will connect you
|
150
|
+
to the development database. Passing an argument will connect you to a different
|
151
|
+
database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
|
152
|
+
PostgreSQL and SQLite 3.
|
153
|
+
|
154
|
+
== Description of Contents
|
155
|
+
|
156
|
+
The default directory structure of a generated Ruby on Rails application:
|
157
|
+
|
158
|
+
|-- app
|
159
|
+
| |-- assets
|
160
|
+
| | |-- images
|
161
|
+
| | |-- javascripts
|
162
|
+
| | `-- stylesheets
|
163
|
+
| |-- controllers
|
164
|
+
| |-- helpers
|
165
|
+
| |-- mailers
|
166
|
+
| |-- models
|
167
|
+
| `-- views
|
168
|
+
| `-- layouts
|
169
|
+
|-- config
|
170
|
+
| |-- environments
|
171
|
+
| |-- initializers
|
172
|
+
| `-- locales
|
173
|
+
|-- db
|
174
|
+
|-- doc
|
175
|
+
|-- lib
|
176
|
+
| |-- assets
|
177
|
+
| `-- tasks
|
178
|
+
|-- log
|
179
|
+
|-- public
|
180
|
+
|-- script
|
181
|
+
|-- test
|
182
|
+
| |-- fixtures
|
183
|
+
| |-- functional
|
184
|
+
| |-- integration
|
185
|
+
| |-- performance
|
186
|
+
| `-- unit
|
187
|
+
|-- tmp
|
188
|
+
| `-- cache
|
189
|
+
| `-- assets
|
190
|
+
`-- vendor
|
191
|
+
|-- assets
|
192
|
+
| |-- javascripts
|
193
|
+
| `-- stylesheets
|
194
|
+
`-- plugins
|
195
|
+
|
196
|
+
app
|
197
|
+
Holds all the code that's specific to this particular application.
|
198
|
+
|
199
|
+
app/assets
|
200
|
+
Contains subdirectories for images, stylesheets, and JavaScript files.
|
201
|
+
|
202
|
+
app/controllers
|
203
|
+
Holds controllers that should be named like weblogs_controller.rb for
|
204
|
+
automated URL mapping. All controllers should descend from
|
205
|
+
ApplicationController which itself descends from ActionController::Base.
|
206
|
+
|
207
|
+
app/models
|
208
|
+
Holds models that should be named like post.rb. Models descend from
|
209
|
+
ActiveRecord::Base by default.
|
210
|
+
|
211
|
+
app/views
|
212
|
+
Holds the template files for the view that should be named like
|
213
|
+
weblogs/index.html.erb for the WeblogsController#index action. All views use
|
214
|
+
eRuby syntax by default.
|
215
|
+
|
216
|
+
app/views/layouts
|
217
|
+
Holds the template files for layouts to be used with views. This models the
|
218
|
+
common header/footer method of wrapping views. In your views, define a layout
|
219
|
+
using the <tt>layout :default</tt> and create a file named default.html.erb.
|
220
|
+
Inside default.html.erb, call <% yield %> to render the view using this
|
221
|
+
layout.
|
222
|
+
|
223
|
+
app/helpers
|
224
|
+
Holds view helpers that should be named like weblogs_helper.rb. These are
|
225
|
+
generated for you automatically when using generators for controllers.
|
226
|
+
Helpers can be used to wrap functionality for your views into methods.
|
227
|
+
|
228
|
+
config
|
229
|
+
Configuration files for the Rails environment, the routing map, the database,
|
230
|
+
and other dependencies.
|
231
|
+
|
232
|
+
db
|
233
|
+
Contains the database schema in schema.rb. db/migrate contains all the
|
234
|
+
sequence of Migrations for your schema.
|
235
|
+
|
236
|
+
doc
|
237
|
+
This directory is where your application documentation will be stored when
|
238
|
+
generated using <tt>rake doc:app</tt>
|
239
|
+
|
240
|
+
lib
|
241
|
+
Application specific libraries. Basically, any kind of custom code that
|
242
|
+
doesn't belong under controllers, models, or helpers. This directory is in
|
243
|
+
the load path.
|
244
|
+
|
245
|
+
public
|
246
|
+
The directory available for the web server. Also contains the dispatchers and the
|
247
|
+
default HTML files. This should be set as the DOCUMENT_ROOT of your web
|
248
|
+
server.
|
249
|
+
|
250
|
+
script
|
251
|
+
Helper scripts for automation and generation.
|
252
|
+
|
253
|
+
test
|
254
|
+
Unit and functional tests along with fixtures. When using the rails generate
|
255
|
+
command, template test files will be generated for you and placed in this
|
256
|
+
directory.
|
257
|
+
|
258
|
+
vendor
|
259
|
+
External libraries that the application depends on. Also includes the plugins
|
260
|
+
subdirectory. If the app has frozen rails, those gems also go here, under
|
261
|
+
vendor/rails/. This directory is in the load path.
|