I am having a really tough time figuring this out. I followed the
tutorial below to add a RESTful authentication to a Ruby application
that tracks projects (just a title and a url). The tutorial is for a
blog, but I just changed blog to projects
Hello Mark, thank you for your suggestion. I gather that the RESTful
ACL plugin is meant to be used instead of RESTful Authentication Plugin
that I am currently using?
Table 'users' already has an implicit 'id' field (you don't have to
mention them in your migrations), just like your 'links' table does. If
you are sticking to the rails standard, you needn't declare them, they
are the rails default primary key for their respective tables.
In your 'links' table, a 'user_id' field tells rails that:
a) this field, 'user_id', contains an id to a record in another table -
i.e., this record "belongs to" that record in that table over there,
and that
b) the related table is 'users' (field name - '_id', pluralized).
Thanks for letting me know. In links/new, how would I go about
including the current user_id? The only way I know of would be a hidden
form element, and I would like to keep it all server side.
Hi Cisco,
I will post my solution later tonight. I'm at work so I don't have
access.
Thanks for letting me know. In links/new, how would I go about
including the current user_id? The only way I know of would be a hidden
form element, and I would like to keep it all server side.
Restful Authentication has the notion of current_user, does it not?
Check in the authenticated_system.rb file in lib for a peek at some
methods you have available to you.
There's no need to know the current_user's id in the links controller's
new action, that just needs to manufacture an @link for the new.html.erb
form.
You will need it for the create action in the links controller though.
Something like:
def create
@link = Link.new(params[:link])
if logged_in?
@link.user_id = current_user.id
if @link.save
redirect_to(@link)
else
render :action => 'new'
end
else
# redirect to your login page?
# I'd actually defend this method with a before_filter, and get
# rid of this if logged_in? stuff
end
end