Commit 2e68c016 by liyijie

Update README.md

parent f0f9e538
...@@ -62,7 +62,7 @@ Or: ...@@ -62,7 +62,7 @@ Or:
```ruby ```ruby
class ProjectsController < SimpleController::BaseController class ProjectsController < SimpleController::BaseController
actions :all, :except => [ :edit, :update, :destroy ] actions :all, except: [ :edit, :update, :destroy ]
end end
``` ```
...@@ -87,8 +87,7 @@ resource is a `User`: ...@@ -87,8 +87,7 @@ resource is a `User`:
```ruby ```ruby
class AccountsController < SimpleController::BaseController class AccountsController < SimpleController::BaseController
defaults :resource_class => User, :collection_name => 'users', :instance_name defaults resource_class: User, collection_name: 'users', instance_name: 'user'
=> 'user'
end end
``` ```
...@@ -101,7 +100,7 @@ different route prefix you can do the following: ...@@ -101,7 +100,7 @@ different route prefix you can do the following:
```ruby ```ruby
class Administrators::PeopleController < SimpleController::BaseController class Administrators::PeopleController < SimpleController::BaseController
defaults :route_prefix => 'admin' defaults route_prefix: 'admin'
end end
``` ```
...@@ -118,7 +117,7 @@ class ProjectsController < SimpleController::BaseController ...@@ -118,7 +117,7 @@ class ProjectsController < SimpleController::BaseController
protected protected
def collection def collection
get_collection_ivar || get_collection_ivar ||
set_collection_ivar(end_of_association_chain.paginate(:page => params[:page])) set_collection_ivar(end_of_association_chain.paginate(page: params[:page]))
end end
end end
``` ```
...@@ -126,6 +125,15 @@ end ...@@ -126,6 +125,15 @@ end
The `end_of_association_chain` returns your resource after nesting all The `end_of_association_chain` returns your resource after nesting all
associations and scopes (more about this below). associations and scopes (more about this below).
The `after_association_chain` add some scope or relation codes for the
`end_of_association_chain`:
```ruby
def after_association_chain association
association.top #top is the scope
end
```
SimpleController also introduces another method called `begin_of_association_chain`. SimpleController also introduces another method called `begin_of_association_chain`.
It's mostly used when you want to create resources based on the `@current_user` and It's mostly used when you want to create resources based on the `@current_user` and
you have urls like "account/projects". In such cases you have to do you have urls like "account/projects". In such cases you have to do
...@@ -191,7 +199,7 @@ would with flash): ...@@ -191,7 +199,7 @@ would with flash):
```ruby ```ruby
class ProjectsController < SimpleController::BaseController class ProjectsController < SimpleController::BaseController
def create def create
create!(:notice => "Dude! Nice job creating that project.") create!(notice: "Dude! Nice job creating that project.")
end end
end end
``` ```
...@@ -201,7 +209,7 @@ You can still pass the block to change the redirect, as mentioned above: ...@@ -201,7 +209,7 @@ You can still pass the block to change the redirect, as mentioned above:
```ruby ```ruby
class ProjectsController < SimpleController::BaseController class ProjectsController < SimpleController::BaseController
def create def create
create!(:notice => "Dude! Nice job creating that project.") { root_url } create!(notice: "Dude! Nice job creating that project.") { root_url }
end end
end end
``` ```
...@@ -290,7 +298,7 @@ Example: ...@@ -290,7 +298,7 @@ Example:
```ruby ```ruby
class ButtonsController < SimpleController::BaseController class ButtonsController < SimpleController::BaseController
belongs_to :window belongs_to :window
actions :all, :except => [:show, :index] actions :all, except: [:show, :index]
end end
``` ```
...@@ -330,7 +338,7 @@ customize how SimpleController find your projects: ...@@ -330,7 +338,7 @@ customize how SimpleController find your projects:
```ruby ```ruby
class TasksController < SimpleController::BaseController class TasksController < SimpleController::BaseController
belongs_to :project, :finder => :find_by_title!, :param => :project_title belongs_to :project, finder: :find_by_title!, param: :project_title
end end
``` ```
...@@ -356,7 +364,7 @@ blocks: ...@@ -356,7 +364,7 @@ blocks:
```ruby ```ruby
class CommentsController < SimpleController::BaseController class CommentsController < SimpleController::BaseController
belongs_to :project, :finder => :find_by_title!, :param => :project_title do belongs_to :project, finder: :find_by_title!, param: :project_title do
belongs_to :task belongs_to :task
end end
end end
...@@ -381,7 +389,7 @@ use polymorphism: ...@@ -381,7 +389,7 @@ use polymorphism:
```ruby ```ruby
class CommentsController < SimpleController::BaseController class CommentsController < SimpleController::BaseController
belongs_to :task, :file, :message, :polymorphic => true belongs_to :task, :file, :message, polymorphic: true
# polymorphic_belongs_to :task, :file, :message # polymorphic_belongs_to :task, :file, :message
end end
``` ```
...@@ -391,7 +399,7 @@ You can even use it with nested resources: ...@@ -391,7 +399,7 @@ You can even use it with nested resources:
```ruby ```ruby
class CommentsController < SimpleController::BaseController class CommentsController < SimpleController::BaseController
belongs_to :project do belongs_to :project do
belongs_to :task, :file, :message, :polymorphic => true belongs_to :task, :file, :message, polymorphic: true
end end
end end
``` ```
...@@ -425,7 +433,7 @@ doing: ...@@ -425,7 +433,7 @@ doing:
```ruby ```ruby
class CommentsController < SimpleController::BaseController class CommentsController < SimpleController::BaseController
belongs_to :task, :file, :message, :optional => true belongs_to :task, :file, :message, optional: true
# optional_belongs_to :task, :file, :message # optional_belongs_to :task, :file, :message
end end
``` ```
...@@ -462,7 +470,7 @@ give the ...@@ -462,7 +470,7 @@ give the
```ruby ```ruby
class ManagersController < SimpleController::BaseController class ManagersController < SimpleController::BaseController
defaults :singleton => true defaults singleton: true
belongs_to :project belongs_to :project
# singleton_belongs_to :project # singleton_belongs_to :project
end end
...@@ -475,9 +483,9 @@ declare it separately ...@@ -475,9 +483,9 @@ declare it separately
```ruby ```ruby
class WorkersController < SimpleController::BaseController class WorkersController < SimpleController::BaseController
#defaults :singleton => true #if you have only single worker #defaults singleton: true #if you have only single worker
belongs_to :project belongs_to :project
belongs_to :manager, :singleton => true belongs_to :manager, singleton: true
end end
``` ```
...@@ -542,7 +550,7 @@ Those urls helpers also accepts a hash as options, just as in named routes. ...@@ -542,7 +550,7 @@ Those urls helpers also accepts a hash as options, just as in named routes.
```ruby ```ruby
# /projects/1/tasks # /projects/1/tasks
collection_url(:page => 1, :limit => 10) #=> /projects/1/tasks?page=1&limit=10 collection_url(page: 1, limit: 10) #=> /projects/1/tasks?page=1&limit=10
``` ```
In polymorphic cases, you can also give the parent as parameter to In polymorphic cases, you can also give the parent as parameter to
...@@ -559,7 +567,7 @@ controller: ...@@ -559,7 +567,7 @@ controller:
```ruby ```ruby
class ButtonsController < SimpleController::BaseController class ButtonsController < SimpleController::BaseController
custom_actions :resource => :delete, :collection => :search custom_actions resource: :delete, collection: :search
end end
``` ```
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment