我是Ruby on Rails中的新手。我想在我的應用程序中執行this註冊嚮導。我已將jquery複製到名爲的文件signup_validation.js並將該文件包含在/ assets/javascripts文件夾中。在Ruby On Rails中使用jquery
我已將HTML代碼包含在我的視圖中。現在,我如何包含該JavaScript文件,以便註冊嚮導以與本教程中相同的方式工作。
這裏是new.html.erb文件
<script type="text/javascript" src="/javascripts/signup_validation.js"></script>
<h2>Sign up</h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<form id="example-advanced-form" action="#">
<h3>Account</h3>
<fieldset>
<legend>Account Information</legend>
<label for="userName-2">User name *</label>
<input id="userName-2" name="userName" type="text" class="required">
<label for="password-2">Password *</label>
<input id="password-2" name="password" type="text" class="required">
<label for="confirm-2">Confirm Password *</label>
<input id="confirm-2" name="confirm" type="text" class="required">
<p>(*) Mandatory</p>
</fieldset>
<h3>Profile</h3>
<fieldset>
<legend>Profile Information</legend>
<label for="name-2">First name *</label>
<input id="name-2" name="name" type="text" class="required">
<label for="surname-2">Last name *</label>
<input id="surname-2" name="surname" type="text" class="required">
<label for="email-2">Email *</label>
<input id="email-2" name="email" type="text" class="required email">
<label for="address-2">Address</label>
<input id="address-2" name="address" type="text">
<label for="age-2">Age (The warning step will show up if age is less than 18) *</label>
<input id="age-2" name="age" type="text" class="required number">
<p>(*) Mandatory</p>
</fieldset>
</form>
<% end %>
<%= render "devise/shared/links" %>
這裏是的application.js文件。
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
//= require signup_validation
使用'javascript_include_tag( 'signup_validation')'在''
?!? – Fallenhero無需單獨包含它。看看你的application.js,看看需要其他庫的行。如果你有'需要樹',你已經設置好了。否則,您也可以繼續添加庫以包含在那裏。 Rails資產管道將爲您進行連接並自動包含您的文件。 –
在頁面刷新後工作嗎? =>可能是一個turbolink問題? –