# What is protected?

**URL:** <https://www.ruby-forum.com/t/what-is-protected/97344>\
**Category:** Rails\
**Created:** [July 6, 2006, 2:21pm UTC](https://www.ruby-forum.com/t/what-is-protected/97344 "2006-07-06T14:21:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [July 6, 2006, 2:21pm UTC](https://www.ruby-forum.com/t/what-is-protected/97344/1 "2006-07-06T14:21:43Z")

</div>

In [http://www.aidanf.net/rails\_user\_authentication\_tutorial](http://www.aidanf.net/rails_user_authentication_tutorial) there is the  
string/method

protected

in the model. What does it do? Can’t find that in  
[http://api.rubyonrails.org/](http://api.rubyonrails.org/).

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [July 6, 2006, 2:51pm UTC](https://www.ruby-forum.com/t/what-is-protected/97344/2 "2006-07-06T14:51:19Z")

</div>

This is OOP visibility encapsulate mechanism.  
Learn more at:  
[Object-oriented programming - Wikipedia](http://en.wikipedia.org/wiki/Object-oriented_programming).

On 7/6/06, PÃ¥l BergstrÃ¶m [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Everton J. Carpes  
Mobile: +55 53 9129.4593  
MSN: removed\_email\_address@domain.invalid  
UIN: 343716195  
Jabber: removed\_email\_address@domain.invalid  
Gestum  
[http://www.gestum.com.br/](http://www.gestum.com.br/)  
O.S. Systems  
[http://www.ossystems.com.br](http://www.ossystems.com.br)  
[http://projects.ossystems.com.br](http://projects.ossystems.com.br)

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [July 6, 2006, 3:06pm UTC](https://www.ruby-forum.com/t/what-is-protected/97344/3 "2006-07-06T15:06:04Z")

</div>

Everton J. Carpes wrote:

> This is OOP visibility encapsulate mechanism.  
> Learn more at:  
> [Object-oriented programming - Wikipedia](http://en.wikipedia.org/wiki/Object-oriented_programming).

thanks 🙂

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [July 6, 2006, 3:16pm UTC](https://www.ruby-forum.com/t/what-is-protected/97344/4 "2006-07-06T15:16:28Z")

</div>

Protected methods can only be invoked via the class itself (and  
friends).

Practically, in rails controllers, this means the method can’t be  
accessed via the web.

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [July 6, 2006, 3:23pm UTC](https://www.ruby-forum.com/t/what-is-protected/97344/5 "2006-07-06T15:23:14Z")

</div>

PÃ¥l BergstrÃ¶m wrote:

> In [http://www.aidanf.net/rails\_user\_authentication\_tutorial](http://www.aidanf.net/rails_user_authentication_tutorial) there is the  
> string/method
> 
> protected
> 
> in the model. What does it do? Can’t find that in  
> [http://api.rubyonrails.org/](http://api.rubyonrails.org/).

It’s a feature of Ruby, not of Rails.

Within a class definition, it marks the following methods as protected  
(i.e. accessible to that class and its subclasses, not accessible to  
other classes).

‘public’ (accessible to any class) and ‘private’ (accessible only to  
this class) work similarly.

In Rails controllers you should take care to make methods that are not  
to be used as actions via HTTP either private or protected.

regards

Justin

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [July 6, 2006, 5:41pm UTC](https://www.ruby-forum.com/t/what-is-protected/97344/6 "2006-07-06T17:41:31Z")

</div>

Inge JÃ¸rgensen wrote:

> Protected methods can only be invoked via the class itself (and  
> friends).
> 
> Practically, in rails controllers, this means the method can’t be  
> accessed via the web.

Not sure I follow.
