You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[RubyGems](http://rubygems.org) is the preferred way to install <tt>BreadcrumbsOnRails</tt> and the best way if you want install a stable version.
19
+
[RubyGems](https://rubygems.org) is the preferred way to install <tt>BreadcrumbsOnRails</tt> and the best way if you want install a stable version.
20
20
21
21
$ gem install breadcrumbs_on_rails
22
22
@@ -27,69 +27,197 @@ Specify the Gem dependency in the [Bundler](http://bundler.io/) `Gemfile`.
27
27
Use [Bundler](http://bundler.io/) and the `:git` option if you want to grab the latest version from the Git repository.
28
28
29
29
30
-
## Basic Usage
30
+
## Usage
31
31
32
32
Creating a breadcrumb navigation menu in your Rails app using <tt>BreadcrumbsOnRails</tt> is really straightforward.
33
33
34
34
In your controller, call `add_breadcrumb` to push a new element on the breadcrumb stack. `add_breadcrumb` requires two arguments: the name of the breadcrumb and the target path.
35
35
36
-
class MyController
37
-
38
-
add_breadcrumb "home", :root_path
39
-
add_breadcrumb "my", :my_path
40
-
41
-
def index
42
-
# ...
43
-
44
-
add_breadcrumb "index", index_path
45
-
end
46
-
47
-
end
36
+
```ruby
37
+
classMyController
48
38
49
-
The third, optional argument is a Hash of options to customize the breadcrumb link.
More complex customizations require a custom @Builder@.
103
+
104
+
### Breadcrumb Element
105
+
106
+
A breadcrumbs menu is composed by a number of `Element` objects. Each object contains two attributes: the name of the breadcrumb and the target path.
107
+
108
+
When you call `add_breadcrumb`, the method automatically creates a new `Element` object for you and append it to the breadcrumbs stack. `Element` name and path can be one of the following Ruby types:
109
+
110
+
-`Symbol`
111
+
-`Proc`
112
+
-`String`
113
+
114
+
#### Symbol
115
+
116
+
If the value is a `Symbol`, the library calls the corresponding method defined in the same context the and sets the `Element` attribute to the returned value.
117
+
118
+
```ruby
119
+
classMyController
120
+
121
+
# The Name is set to the value returned by
122
+
# the :root_name method.
123
+
add_breadcrumb :root_name, "/"
124
+
125
+
protected
126
+
127
+
defroot_name
128
+
"the name"
129
+
end
130
+
131
+
end
132
+
```
133
+
134
+
#### Proc
135
+
136
+
If the value is a `Proc`, the library calls the proc passing the current view context as argument and sets the `Element` attribute to the returned value. This is useful if you want to postpone the execution to get access to some special methods/variables created in your controller action.
If the value is a `String`, the library sets the `Element` attribute to the string value.
152
+
153
+
```ruby
154
+
classMyController
155
+
156
+
# The Name is set to the value returned by
157
+
# the :root_name method.
158
+
add_breadcrumb "homepage", "/"
159
+
160
+
end
161
+
```
162
+
163
+
### Restricting breadcrumb scope
164
+
165
+
The `add_breadcrumb` method understands all options you are used to pass to a Rails controller filter. In fact, behind the scenes this method uses a `before_filter` to store the tab in the `@breadcrumbs` variable.
166
+
167
+
Taking advantage of Rails filter options, you can restrict a tab to a selected group of actions in the same controller.
0 commit comments