# Options

**URL:** <https://www.ruby-forum.com/t/options/176560>\
**Category:** Rails\
**Created:** [October 2, 2009, 5:57am UTC](https://www.ruby-forum.com/t/options/176560 "2009-10-02T05:57:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![corneto82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@corneto82](https://www.ruby-forum.com/u/corneto82)\
**Post date:** [October 2, 2009, 5:57am UTC](https://www.ruby-forum.com/t/options/176560/1 "2009-10-02T05:57:10Z")

</div>

Hi Group! I started working with Rails about a week ago.  
I created this app that acts pretty much like a public blog. So far  
users can register for an account with Authlogic ([http://github.com/](http://github.com/)  
binarylogic/authlogic). Once a user has logged in they can add their  
own posts. Now I would like to make it so that only posts authors are  
able to edit or destroy their own items.  
Using this tutorial ([http://wiki.github.com/be9/acl9/tutorial-securing-](http://wiki.github.com/be9/acl9/tutorial-securing-)  
a-controller) I did the following:

–\>This is in my PostsControllers

## class PostsController \< ApplicationController before\_filter :load\_post, :only =\> [:edit, :update, :destroy, :show] access\_control do allow all, :to =\> [:index, :show] allow :admin allow logged\_in, :to =\> [:new, :create] allow :owner, :manager, :of =\> :post, :to =\> [:edit, :update] end â€¦ private def load\_post @post= Post.find(params[:id]) end end

So far so good. Now I need set the role for each user to manage their  
own post.

Following the same tutorial I can only get to accomplish this by doing  
this to my PostsControllers

## def create @post = Post.new(params[:product]) if @post.save flash[:notice] = â€˜Post created.â€™ current\_user.has\_role!(:author, @post # \<â€”â€”â€”â€”- assign the role redirect\_to(@post) else render :new end end

That works, but not quite. The only problem is how it gets stored in  
the database.

For every time a user creates a new post it adds data to the table  
“roles” and “roles\_users”, so if the same user adds another post this  
would add another row to “roles”, “roles\_user”, and of course to  
“posts”.

I believe this would work better (and be lighter in the database) if  
the role would be set at the time the user is created…so the user  
has a role over any post that has its user\_id.

Can anybody help me solve this? Your assistance would be very greatly  
appreciated. Thanks for your time 😉
