views:

109

answers:

1

http://github.com/samliu/rlinkset

^^ My code so far is pushed to there.

Essentially, I'm using resource_controller and I don't really understand resource_controller. When I used scaffolding to create my Post model, I gave it fields like

:integer parent #to say what level a post is at (which post ID is this post's parent)
:integer user_id #I meant for this to hold something like @user.id

Now, the scaffold form created lets me put in those values. however, I want them to be put in automatically from the controller and not to be something the user submits. Like, in the backend logic, I need to set @post.user_id = @user.id or something like that.

However, since resource_controller hides all the methods like create, index, new, edit, destroy, whatever, I can't find where to edit the function I need.

I'm very new at TDD and RESTful design. I worked did some basic rails/ruby stuff in the past but haven't touched it for a while until now.

Would appreciate some guidance! :)

+1  A: 

My first suggestion would be to not use ResourceController until you are more comfortable with Rails. You can still do TDD and RESTful design with the scaffolds- they are RESTful.

If you stick with ResourceController, do:

class PostsController < ResourceController::Base
  create.before do
    @post.user_id << current_user.id
  end
end
MattMcKnight
ah wow I saw this in the resource_controller doc...gosh I must have been tired or something, haha. solved my problems, thanks! :)
Sam