我正在开发一个主要由静态页面组成的投资组合网站,我试图创建一种效果,使该网站作为一个页面无缝运行(从主页到主页),因此我需要使用 Javascript/Jquery。
由于某种原因,当我从一个静态页面 link_to 到另一个静态页面时,我的 format.js 代码没有被执行。这是我的代码
导航 Controller
def home
respond_to do |format|
format.js
format.html
end
end
def main
end
在 View (home.html.erb) 中我有
<%= link_to navigation_main_path, remote: true do %>
<h2> ENTER SITE </h2>
<% end %>
和routes.rb
get 'navigation/home'
get 'navigation/main'
root to: 'navigation#home'
用于测试目的的我的format.js.erb,位于app/views/navigation中
alert('hi');
我根本无法弄清楚这一点,希望得到任何帮助。
最佳答案
在您的代码中尝试使用格式选项
<%= link_to navigation_main_path(format: :js), remote: true do %>
关于javascript - Rails Javascript 不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45646481/