Javascript Ruby-on-Rails:openmodalbox-Link不';t工作更新:链接到远程

Javascript Ruby-on-Rails:openmodalbox-Link不';t工作更新:链接到远程,javascript,jquery,ruby-on-rails,ruby,link-to-remote,Javascript,Jquery,Ruby On Rails,Ruby,Link To Remote,我希望我的页面打开一个模式弹出框,因此我将此链接添加到我的视图文件: <%= link_to_remote '+ Add Discount', :url => {:controller => "parent_wise_fee_payments", :action => "new_instant_discount", :id => @financefee.id, :current_action => @target_action, :current_cont

我希望我的页面打开一个模式弹出框,因此我将此链接添加到我的视图文件:

  <%= link_to_remote '+ Add Discount', :url => {:controller => "parent_wise_fee_payments", :action => "new_instant_discount", :id => @financefee.id, :current_action => @target_action, :current_controller => @target_controller} %>
然后我创建了create_instant_折扣操作并使用以下代码创建了_instant_dicount.rjs:

page.replace_html 'modal-box', :partial => 'instant_discount_form'
page << "Modalbox.show($('modal-box'),  {title: ''});"

尝试创建新的即时折扣.rjs。然后把它放在那里:

page.replace_html 'modal-box', :partial => 'instant_discount_form'
page << "Modalbox.show($('modal-box'),  {title: ''});"
page.replace\u html“模式框”,:partial=>“即时折扣表单”
页
你能帮我找出我遗漏了什么吗

如果你没有看到任何结果,那么问题可能出在你的电脑上

Rails无法为您打开模型,它必须使用服务器返回的数据附加到DOM中。看起来您正在将请求发送到服务器好的,这只是一个将请求返回并附加到服务器的例子


代码

当前的代码非常随意,这就是我对您提供的代码所做的:

--

系统

您的问题不仅仅是没有收到数据的直接回报,还需要了解代码的结构(几乎就在那里)

现在,从path helper的荒谬之处,我相信您可以理解如何能够解决系统中的一些更深层次的问题。也就是说,你对你的控制者/行动很具体;它需要用于数据对象:

#config/routes.rb 
resources :finance_fees do
   resources :discounts
end

#app/controllers/discounts_controller.rb
class DiscountsController < ApplicationController
   def new
      @finance_fee = FinanceFee.find params[:finance_fee_id]
      @discount = @finance_fee.discounts.new
   end
   def create
      @finance_fee = FinanceFee.find params[:finance_fee_id]
      @discount = @finance_fee.discounts.new create_params          
   end
   private
   def create_params
      params.require(:discount).permit(:x, :y, :z)
   end
end
这会将数据异步发送到服务器,不会处理响应。如果您使用以下选项,它应该可以工作:

<%= link_to '+ Add Discount', :url => {:controller => "parent_wise_fee_payments", :action => "new_instant_discount", :id => @financefee.id, :current_action => @target_action, :current_controller => @target_controller}, remote: true %>
{:controller=>“家长明智的费用支付”,:action=>“新的即时折扣”,:id=>@financefee.id,:current\u action=>@target\u action,:current\u controller=>@target\u controller},remote:true%>

非常感谢您的解释!
#app/views/controller/action.js.erb
$modalbox = $('modal-box');
$modalbox.html("<%=j render 'instant_discount_form' %>");
$('body').append(Modalbox.show($modalbox,  {title: ''}));
#app/views/controller/action.js.erb
$modalbox = $('modal-box');
$modalbox.html("<%=j render 'instant_discount_form' %>");
$('body').append(Modalbox.show($modalbox,  {title: ''}));

console.log($modalbox); //checks if $('modal-box') is valid
console.log(Modalbox.show($modalbox,  {title: ''})); // checks if Modal being called correctly.
<%= link_to_remote '+ Add Discount', :url => {:controller =>  "parent_wise_fee_payments", :action => "new_instant_discount", :id =>  @financefee.id, :current_action => @target_action, :current_controller => @target_controller} %>
<%= link_to_remote '+ Add Discount', parent_wise_fee_payements_new_instant_discount_path(id: @financefee.id, current_action: @target_action, current_controller: @target_controller) %>
#config/routes.rb 
resources :finance_fees do
   resources :discounts
end

#app/controllers/discounts_controller.rb
class DiscountsController < ApplicationController
   def new
      @finance_fee = FinanceFee.find params[:finance_fee_id]
      @discount = @finance_fee.discounts.new
   end
   def create
      @finance_fee = FinanceFee.find params[:finance_fee_id]
      @discount = @finance_fee.discounts.new create_params          
   end
   private
   def create_params
      params.require(:discount).permit(:x, :y, :z)
   end
end
<%= link_to "link", link_path, remote: true %>
<%= link_to '+ Add Discount', :url => {:controller => "parent_wise_fee_payments", :action => "new_instant_discount", :id => @financefee.id, :current_action => @target_action, :current_controller => @target_controller}, remote: true %>