首页 > 解决方案 > 隔离导轨插件上的远程链接不起作用

问题描述

我在将远程链接添加到隔离的 Rails 插件时遇到问题。当我单击链接时,它什么也不做。我什至没有收到任何错误消息,它什么也没做。

这是链接:

<!-- app/views/my_plugin/models/new.html.erb -->
...
<fieldset id="attrs">
  <legend><%= t 'my_plugin.attrs' %></legend>
<%= link_to t('my_plugin.new_attr'), models_add_attr_url, :remote => true %>
</fieldset>
...

这是我的路线:

# config/routes.rb
MyPlugin::Engine.routes.draw do  
...
  get 'models/add_attr'
end

这是我的控制器:

# app/controllers/my_plugin/models_controller.rb
require_dependency "my_plugin/application_controller"

module MyPlugin
  class ModelsController < ApplicationController
...
    # GET /models/add_attr
    def add_attr
      respond_to { |format| format.js }
    end
...
  end
end

这是我的js文件,只是一个测试:

// app/views/my_plugin/models/add_attr.js.erb
console.log('hello'); 

这是我的引擎:

# lib/my_plugin/engine.rb
module MyPlugin
  class Engine < ::Rails::Engine
    require 'jquery-rails'
    require 'turbolinks'
    isolate_namespace MyPlugin
  end    
end

这是我的宝石规格:

# my_plugin.gemspec
...
Gem::Specification.new do |spec|
...
  spec.add_dependency "rails", "~> 5.2"
  spec.add_dependency 'jquery-rails', '~> 4.3'
  spec.add_dependency 'turbolinks', '~> 5.2'
...
end

我希望我提供了足够的信息。谢谢你的帮助。

标签: javascriptruby-on-railsrubyruby-on-rails-plugins

解决方案


推荐阅读