这是我的观点,我尝试遵循一些教程并最终从http://8raystech.com/2011/11/28/how-to-create-embeddable-widgets-with-rails阅读了所有的参考资料。
由于我对ruby on rails不熟悉,在搜索了近2天后,我认为这可能是路由错误。因为当我通过Chrome检查元素时,发现以下错误:编辑:
我尝试了很多方法,但这是我目前的代码:
我的小部件控制器看起来像这样:(widget_controller.rb)
最后,在routes.rb文件中。
"GET http://localhost:3000/widget 500 (Internal Server Error)"
我尝试了很多方法,但这是我目前的代码:
我的小部件控制器看起来像这样:(widget_controller.rb)
class WidgetController < ApplicationController
def show
@content = render_to_string(:partial => 'widget/embed', :layout => false)
end
end
我使用JavaScript的观点(show.erb.html)
(function() {
document.write(<%= @content.to_json %>)
})()
我觉得这个部分并不是很重要,但是下面是一个例子:(_embed.erb.html)
<style>...</style>
<div class="widget-communication">
<div>Bla bla bla</div>
...
</div>
最后,在routes.rb文件中。
...
match 'widget', to: 'widget#show'
...
所以我在本地测试了使用以下代码加载我的小部件:
<script src="http://localhost:3000/widget" type="text/javascript"></script>