开发者

Posting with Nested Resources

I have nested my resources (see below) and when I try to create a new entity, I get the following error. Does anyone know why I'm getting this error and how to solve it?

undefined method `applications' for nil:NilClass

resources careers do
    resources applications
end

Within the 'Applications' controller I have:

before_filter [[:authenticate, :except => 开发者_高级运维:new], :load_career]

def create
      # The following line is where the error originates
    @application = @career.applications.new(params[:application])

    respond_to do |format|
        ...
    end
end

private
def load_career
    @career = Career.find(params[:career_id])
end

The Career and Application models have has_many :applications and belongs_to :career respectively.

And the '*_create_applications' migration has a career_id field.


I have never seen before_filters defined that way. I just tried it in Rails 3 and it doesn't seem to do anything. I would give each callback it's own before_filter call:

before_filter :authenticate, :except => :new
before_filter :load_career
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜