如何在AJAX中使用邪恶的精灵宝石?

如何在AJAX中使用邪恶的精灵宝石?

问题描述:

我正在使用wicked来创建一个多步向导。我想使用AJAX,这样我就可以浏览表单而不必重新加载页面。我无法在网上找到有关如何执行此操作的任何信息。有没有人做过这个?如何在AJAX中使用邪恶的精灵宝石?

我可能有点晚,但我只是在使用这些相同功能的项目上工作,所以如果有其他人想知道同样的事情,希望这可能会有所帮助。

一般来说,最好设置妖兽就像你会为一个普通的HTML向导:

应用程序/控制器/ set_up_positions_controller.rb

class SetUpPositionController < ApplicationController 

    include Wicked::Wizard 

    steps :appointment_settings, :lab_settings 

    def show 
     case step 
     when :appointment_settings 
     when :lab_settings 
     end 
     render_wizard 
    end 

    def update 
     case step 
     when :appointment_settings 
      #LOGIC 
     when :lab_settings 
      #LOGIC 
     end 
     render_wizard @position 
    end 

end 

从这里的关键是要建立一个既step_name.js.erb和每个步骤的_step_name.html.erb文件。 IE浏览器。

应用程序/视图/ set_up_positions/appointment_settings.js.erb

$('#clinics-content').html('<%= j render "clinic_management/set_up_position/appointment_settings" %>'); 

应用程序/视图/ set_up_positions/_appointment_settings.html.erb

<%= simple_form_for [:clinic_management, @clinic, @position], url: wizard_path, method: :put, remote: true do |f| %> 
    <%= f.input :bill_authorization, collection: bill_authorization_options %> 
    #etc etc 
<% end%> 

你可能会想一些错误添加使用JS文件进行消息传递(现在它调用相同的JS,并在字段名称下呈现错误,在这种情况下可能会或可能不会)。

根据你的用例,它可能也更容易使用这种类型的东西(如steps.js)的JS框架之一。我没有,因为我明白ruby比JS好一点,但对于其他人来说,这也是一种选择。