# Edit only your posts

**URL:** <https://www.ruby-forum.com/t/edit-only-your-posts/181351>\
**Category:** Rails\
**Created:** [January 10, 2010, 3:30pm UTC](https://www.ruby-forum.com/t/edit-only-your-posts/181351 "2010-01-10T15:30:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nexon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b5a626/32.png) [@nexon](https://www.ruby-forum.com/u/nexon)\
**Post date:** [January 10, 2010, 3:30pm UTC](https://www.ruby-forum.com/t/edit-only-your-posts/181351/1 "2010-01-10T15:30:30Z")

</div>

Hello, How can I do, when a user make a post, he only can edit his  
posts?

thanks

---

<div class="post-metadata">

**Author:** ![nexon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b5a626/32.png) [@nexon](https://www.ruby-forum.com/u/nexon)\
**Post date:** [January 10, 2010, 6:33pm UTC](https://www.ruby-forum.com/t/edit-only-your-posts/181351/2 "2010-01-10T18:33:09Z")

</div>

On Sun, Jan 10, 2010 at 11:30 AM, Alberto L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hello, How can I do, when a user make a post, he only can edit his  
> posts?

Check for the owner of the post on the edit action?

---

<div class="post-metadata">

**Author:** ![nexon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b5a626/32.png) [@nexon](https://www.ruby-forum.com/u/nexon)\
**Post date:** [January 10, 2010, 6:35pm UTC](https://www.ruby-forum.com/t/edit-only-your-posts/181351/3 "2010-01-10T18:35:47Z")

</div>

Leonardo M. wrote:

> On Sun, Jan 10, 2010 at 11:30 AM, Alberto L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Hello, How can I do, when a user make a post, he only can edit his  
> > posts?
> 
> Check for the owner of the post on the edit action?

Exactly, if you have an user on my website an post anything, you will  
edit or destroy only your posts.

---

<div class="post-metadata">

**Author:** ![nexon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b5a626/32.png) [@nexon](https://www.ruby-forum.com/u/nexon)\
**Post date:** [January 10, 2010, 7:15pm UTC](https://www.ruby-forum.com/t/edit-only-your-posts/181351/4 "2010-01-10T19:15:53Z")

</div>

2010/1/10 Alberto L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Leonardo M. wrote:
> 
> > On Sun, Jan 10, 2010 at 11:30 AM, Alberto L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > wrote:
> > 
> > > Hello, How can I do, when a user make a post, he only can edit his  
> > > posts?
> > 
> > Check for the owner of the post on the edit action?
> 
> Exactly, if you have an user on my website an post anything, you will  
> edit or destroy only your posts.

I think that Leonardo meant that in the edit and destroy actions you  
should test that the current user is the owner of the post and not  
allow the action to proceed if not the owner.

Colin

---

<div class="post-metadata">

**Author:** ![nexon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b5a626/32.png) [@nexon](https://www.ruby-forum.com/u/nexon)\
**Post date:** [January 10, 2010, 7:25pm UTC](https://www.ruby-forum.com/t/edit-only-your-posts/181351/5 "2010-01-10T19:25:43Z")

</div>

Colin L. wrote:

> 2010/1/10 Alberto L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > Leonardo M. wrote:
> > 
> > > On Sun, Jan 10, 2010 at 11:30 AM, Alberto L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > > wrote:
> > > 
> > > > Hello, How can I do, when a user make a post, he only can edit his  
> > > > posts?
> > > 
> > > Check for the owner of the post on the edit action?
> > 
> > Exactly, if you have an user on my website an post anything, you will  
> > edit or destroy only your posts.
> 
> I think that Leonardo meant that in the edit and destroy actions you  
> should test that the current user is the owner of the post and not  
> allow the action to proceed if not the owner.
> 
> Colin

Aaahm… I think yes. I don’t know another way to make it :S (I’m a  
little bit novice. I know a little bit Ruby but I get into mess with  
some things). I have thought to make a function current\_user probing the  
user by name and make an if sentence : if post.name == current\_user{  
edit, destroy }

For example, but I dont know how to make it exactly… :S (I hear bells  
but i dont know where)

---

<div class="post-metadata">

**Author:** ![nexon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b5a626/32.png) [@nexon](https://www.ruby-forum.com/u/nexon)\
**Post date:** [January 11, 2010, 10:52am UTC](https://www.ruby-forum.com/t/edit-only-your-posts/181351/6 "2010-01-11T10:52:13Z")

</div>

2010/1/10 Alberto L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> …  
> Aaahm… Â I think yes. I don’t know another way to make it :S (I’m a  
> little bit novice. I know a little bit Ruby but I get into mess with  
> some things). I have thought to make a function current\_user probing the  
> user by name and make an if sentence : if post.name == current\_user{  
> edit, destroy }
> 
> For example, but I dont know how to make it exactly… :S (I hear bells  
> but i dont know where)

You need to be reasonably proficient in the use of Ruby to use RoR so  
I would suggest first googling for some Ruby primers and work through  
those. Then (or at the same time if you get bored) work through some  
of the online Rails Guides (google for Rails Guides), particularly  
Getting Started, ActiveRecord Relationships and Debugging.

Another excellent way of learning is to watch this list and any time  
you understand the question then follow the thread and try to  
understand the answer. In no time you will find yourself answering  
questions yourself. You will make a fool of yourself on occasions (at  
least I did, and still do) but do not worry about that.

Colin
