当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby on rails - NoMethodError (undefined method `id' for nil:NilClass)

问题描述:

I'm getting this error when I request via cURL to create a ticket on Redmine. My cURL is creating the ticket successfully but it's is also returning an error and I'm not able to understand why is it so.

Here's the error I'm getting:

Started POST "/issues.json" for 122.161.50.0 at 2016-04-16 07:18:22 +0000

Processing by IssuesController#create as JSON

Parameters: {"issue"=>{"project_id"=>10, "tracker_id"=>7, "status_id"=>1, "priority_id"=>3, "subject"=>"Issue created from CURL"}}

Current user: himanshu (id=3)

Rendered mailer/_issue.text.erb (6.8ms)

Rendered mailer/issue_add.text.erb within layouts/mailer (45.6ms)

Rendered mailer/_issue.html.erb (2.3ms)

Rendered mailer/issue_add.html.erb within layouts/mailer (6.9ms)

Completed 500 Internal Server Error in 724.8ms

NoMethodError (undefined method `id' for nil:NilClass):

lib/redmine/hook.rb:61:in `block (2 levels) in call_hook'

lib/redmine/hook.rb:61:in `each'

lib/redmine/hook.rb:61:in `block in call_hook'

lib/redmine/hook.rb:58:in `tap'

lib/redmine/hook.rb:58:in `call_hook'

lib/redmine/hook.rb:153:in `call_hook'

app/controllers/issues_controller.rb:151:in `create'

This is the controller code

def create

call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })

@issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))

if @issue.save

call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})

respond_to do |format|

format.html {

render_attachment_warning_if_needed(@issue)

flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))

if params[:continue]

attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}

redirect_to new_project_issue_path(@issue.project, :issue => attrs)

else

redirect_to issue_path(@issue)

end

}

format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }

end

return

else

respond_to do |format|

format.html { render :action => 'new' }

format.api { render_validation_errors(@issue) }

end

end

end

This is the code that calls a hook

def call_hook(hook, context={})

[].tap do |response|

hls = hook_listeners(hook)

if hls.any?

hls.each {|listener| response << listener.send(hook, context)}

end

end

end

网友答案:

@Himanshu Upadhyaya, can you show you render_attachment_warning_if_needed, I think it changed your @issue.

And which one is your line 151 in that controller. I need to know.

Please check it

分享给朋友:
您可能感兴趣的文章:
随机阅读: