重定向无法按预期工作轨道5 mogodb mindapp

时间:2017-04-20 11:21:12

标签: ruby-on-rails ruby mongodb mongoid haml

我一直在尝试将我的操作重定向到其他一些操作,但在提交表单后它无法正常工作,数据提交工作正常,但重定向不会按预期启动get请求。请帮帮我。

注意:

重定向在" end_form"之后开始。通过从下面的haml文件提交表单数据来调用action," end_form"调用类方法" end_action"重定向发生的地方。

我的控制器行动:

  def run
   init_vars(params[:id])
   if authorize?
    redirect_to(:action=>"run_#{@runseq.action}", :id=>@xmain.id)
   else
    redirect_to_root
   end
  end
  def run_form
   init_vars(params[:id])
   if authorize?
    if ['F', 'X'].include? @xmain.status
     redirect_to_root
    else
     service = @xmain.service
     if service
      @title= "Transaction ID #{@xmain.xid}: #{@xmain.name} / #{@runseq.name}"
      fhelp= "app/views/#{service.module.code}/#{service.code}/#{@runseq.code}.md"
      @help = File.read(fhelp) if File.exists?(fhelp)
      f= "app/views/#{service.module.code}/#{service.code}/#{@runseq.code}.html.erb"
      @ui= File.read(f)
     else
      # flash[:notice]= "ไม่สามารถค้นหาบริการที่ต้องการได้"
      ma_log "Error: Service not found"
      redirect_to_root
     end
    end
  else
   redirect_to_root
  end
 end
 def end_form
  init_vars(params[:xmain_id])
  eval "@xvars[@runseq.code] = {} unless @xvars[@runseq.code]"
  params.each { |k,v|
   if params[k].respond_to? :original_filename
    get_image(k, params[k])
   elsif params[k].is_a?(Hash)
    eval "@xvars[@runseq.code][k] = v"
    params[k].each { |k1,v1|
      next unless v1.respond_to?(:original_filename)
      get_image1(k, k1, params[k][k1])
    }
   else
    eval "@xvars[@runseq.code][k] = v"
   end
  }
 end_action
end
def end_action(next_runseq = nil)
 @xmain.xvars= @xvars
 @xmain.status= 'R' # running
 @xmain.save
 @runseq.status='F'
 @runseq.user= current_user
 @runseq.stop= Time.now
 @runseq.save
 next_runseq= @xmain.runseqs.where(:rstep=> @runseq.rstep+1).first unless next_runseq
 if @end_job || !next_runseq # job finish
  @xmain.xvars= @xvars
  @xmain.status= 'F' unless @xmain.status== 'E' # finish
  @xmain.stop= Time.now
  @xmain.save
  if @xvars['p']['return']
    redirect_to @xvars['p']['return'] and return
  else
    if @user
      redirect_to :action=>'pending' and return
    else
      redirect_to_root and return
    end
  end
 else
  @xmain.update_attribute :current_runseq, next_runseq.id
  redirect_to :action=>'run', :id=>@xmain.id and return
 end
end

Haml文件:

 .head
 = step(@runseq.form_step, @xvars['total_form_steps'])
 %p
 - user = current_user || User.new
 - form_class = 'formtastic'
 - next_step = 'end_form'
 - if @help
   %div(data-role="collapsible" data-theme="e" data-content-theme="c" data-mini="true")
 %h3 ตำแนะนำ
  %p= markdown(@help)
 = form_tag({ :action => next_step } , {:multipart => true, :onSubmit=>'return validate()', :class=>form_class, "data-ajax"=>"#{ajax?(@ui)}"}) do
  = hidden_field_tag 'xmain_id', @xmain.id
  = hidden_field_tag 'ajax', ajax?(@ui)
  = hidden_field_tag 'runseq_id', @runseq.id
  = hidden_field_tag 'step', @xvars[:current_step]
 %div(data-role="fieldcontain")
 = render :inline=> @ui
%p
= submit_tag NEXT
%p

这是我的服务器状态,在我使用上述表单提交数据后重定向200表示:

Started POST "/mindapp/end_form" for 127.0.0.1 at 2017-04-20 16:31:43 +0530
Processing by MindappController#end_form as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"zvO4P4uf3+tGghitMlsSzXUvA3s2lLAVh64Y/im6etjm5gVmip2sNSPa8LeEyac01r0QvcImIbjqP9V27C9xJA==", "xmain_id"=>"58f89514e8166e45157c54f8", "ajax"=>"true", "runseq_id"=>"58f89514e8166e45157c54f9", "step"=>"1", "code"=>"admin", "commit"=>"Next >"}
param recceived: 58f89514e8166e45157c54f8
MONGODB | localhost:27017 | f241502_development.find | STARTED | {"find"=>"mindapp_xmains", "filter"=>{"_id"=>BSON::ObjectId('58f89514e8166e45157c54f8')}}
MONGODB | localhost:27017 | f241502_development.find | SUCCEEDED | 0.0009284790000000001s
xmain = #<Mindapp::Xmain:0x007f42e9635eb0>
MONGODB | localhost:27017 | f241502_development.find | STARTED | {"find"=>"mindapp_runseqs", "filter"=>{"xmain_id"=>BSON::ObjectId('58f89514e8166e45157c54f8'), "_id"=>BSON::ObjectId('58f89514e8166e45157c54f9')}}
MONGODB | localhost:27017 | f241502_development.find | SUCCEEDED | 0.0021874539999999997s
MONGODB | localhost:27017 | f241502_development.find | STARTED | {"find"=>"users", "filter"=>{"_id"=>BSON::ObjectId('58ee24f9e8166e625e2aef58')}}
MONGODB | localhost:27017 | f241502_development.find | SUCCEEDED | 0.002156202s
MONGODB | localhost:27017 | f241502_development.update | STARTED | {"update"=>"mindapp_xmains", "updates"=>[{"q"=>{"_id"=>BSON::ObjectId('58f89514e8166e45157c54f8')}, "u"=>{"$set"=>{"xvars"=>{"service_id"=>BSON::ObjectId('58ee23dbe8166e625e2aef52'), "p"=>{"s"=>"admins:edit_role", "action"=>"init", "controller"=>"mind...
MONGODB | localhost:27017 | f241502_development.update | SUCCEEDED | 0.001799581s
MONGODB | localhost:27017 | f241502_development.update | STARTED | {"update"=>"mindapp_runseqs", "updates"=>[{"q"=>{"_id"=>BSON::ObjectId('58f89514e8166e45157c54f9')}, "u"=>{"$set"=>{"status"=>"F", "user_id"=>BSON::ObjectId('58ee24f9e8166e625e2aef58'), "stop"=>2017-04-20 11:01:43 UTC, "updated_at"=>2017-04-20 11:01:4...
MONGODB | localhost:27017 | f241502_development.update | SUCCEEDED | 0.000982516s
MONGODB | localhost:27017 | f241502_development.find | STARTED | {"find"=>"mindapp_runseqs", "filter"=>{"xmain_id"=>BSON::ObjectId('58f89514e8166e45157c54f8'), "rstep"=>2}, "sort"=>{"_id"=>1}, "limit"=>1, "singleBatch"=>true}
MONGODB | localhost:27017 | f241502_development.find | SUCCEEDED | 0.003216157s
MONGODB | localhost:27017 | f241502_development.update | STARTED | {"update"=>"mindapp_xmains", "updates"=>[{"q"=>{"_id"=>BSON::ObjectId('58f89514e8166e45157c54f8')}, "u"=>{"$set"=>{"current_runseq"=>"58f89514e8166e45157c54fa", "updated_at"=>2017-04-20 11:01:43 UTC}}, "multi"=>false, "upsert"=>false}], "ordered"=>tru...
MONGODB | localhost:27017 | f241502_development.update | SUCCEEDED | 0.000775832s
next_sequence: 58f89514e8166e45157c54fa
xmain_id: 58f89514e8166e45157c54f8
Redirected to http://localhost:3000/mindapp/run/58f89514e8166e45157c54f8

Completed 200 OK in 29ms

通常重定向看起来像:

Redirected to http://localhost:3000/mindapp/run/58f89514e8166e45157c54f8
Completed 302 Found in 252ms


Started GET "/mindapp/run/58f89514e8166e45157c54f8" for 127.0.0.1 at 2017-04-20 16:31:40 +0530
Processing by MindappController#run as HTML

但是我没有从服务器eacg时间获得这种类型的响应我提交表单。请有人帮忙。

0 个答案:

没有答案