caseyli/capo — comment on commit ad0e6f2e4bb1aa0628951c74ac1a4aafbdc5734d
File: app/controllers/posts_controller.rb line 4
By jduff:

When you have a nested resource you will generally want to load the parent resource first and do all your operations off of that object. I will usually create a `before_filter` to load the parent object for me.

``` ruby
# before filter
def load_open_mic
@open_mic = OpenMic.find(params[:open_mic_id])
end
```

Within this method we can then just do:

``` ruby
@post = @open_mic.posts.new(params[:post])
if @post.save
flash[:success] = "Posted!"
end

redirect_to @open_mic
```

I also left out the `deny_access_for_non_hosts` because this could just be a `before_filter` as well. Just have it after the before filter call for `load_open_mic` and `@open_mic` will be available if it exists.