0

我提前道歉这是我第一次发布问题。这是我的错误,我不理解或不知道如何纠正这是导致错误的代码一切正常,直到这

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
4

1 回答 1

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 允许您省略{}when last 参数是Hash

id @act.save

应该

if @act.save
于 2013-03-28T21:31:22.727 回答