Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
simple_controller
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
simple_controller
Commits
2e68c016
Commit
2e68c016
authored
Jan 06, 2018
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update README.md
parent
f0f9e538
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
18 deletions
+26
-18
README.md
README.md
+26
-18
No files found.
README.md
View file @
2e68c016
...
@@ -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
```
```
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment