Rails错误不明白newb期待tASSOC

时间:2013-03-28 21:21:29

标签: ruby-on-rails ruby ruby-on-rails-3.2

我道歉,这是我第一次发帖提问。 这是我的错误,我不明白或知道如何纠正这是导致错误的代码一切正常,直到这个

c:/Sites/helpdesk/app/controllers/tickets_controller.rb:99:语法错误,意外'=',期待tASSOC     redirect_to:action => 'show',:id = flash [:ticket_id]                                         ^

#action
def ticket_action
  @act = Action.new(
        "ticket_id" => flash[:ticket_id],
        "description" => params[:description]['description'],
        "user_id" => params[:actUser]['user_id']
    )

  id @act.save
    flash[:notice] = 'Action was successfully added'
    redirect_to :action => 'show', :id = flash[:ticket_id]
    end

1 个答案:

答案 0 :(得分:1)

unexpected '=', expecting tASSOC redirect_to :action => 'show', :id = flash[:ticket_id]

tASSOC=>符号,因此ruby期待=>而不是= 只需在行中替换它:

redirect_to :action => 'show', :id => flash[:ticket_id]

相当于:

redirect_to { :action => 'show', :id => flash[:ticket_id] }

Ruby允许您在最后一个参数为{}

时省略Hash

id @act.save

应该是

if @act.save