私は Web 開発の初心者で、現在 Rails の簡単なプロジェクトに取り組んでいます。現在、すべてのエントリに日付があるエントリを含むデータベースがあり、現在の週のすべてのエントリを表示するインデックス ページがありますが、これは正常に機能しています。
次のステップは、ユーザーが週を選択し (現在は jQuery UI 日付ピッカーを使用)、ボタンをクリックするメソッドを実装することです。これにより、インデックス ページの部分が自動的に更新され、その週のエントリが表示されます。
これが私がこれまでに持っているものです:
/app/views/reports/index.html.erb 内
<script>$(function() {
$("#datepicker").datepicker();
$("#datepicker").val($.datepicker.formatDate('mm/dd/yy', new Date()));
});</script>
<% require 'date' %>
<h1>Listing reports</h1>
<input type="datetime" id="datepicker" /> <%= button_to "Select Date", :action => 'showEntries', :remote => 'true' %>
<div id="displayReports">
<%= render 'display', :date => Date.today %>
</div>
<br />
<%= link_to 'New Report', new_report_path %>
<%= link_to 'Send Weekly Email', weekly_email_reports_path %>
/app/views/reports/_display.html.erb 内
<% require 'date' %>
<table>
<tr>
<th>App</th>
<th>Week</th>
<th>Completed</th>
<th>Planned</th>
<th>Releases</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @reports.each do |report| %>
<% if report.entrydate.strftime('%U') == date.strftime('%U') %>
<tr>
<td><%= report.app %></td>
<td><%= report.entrydate %></td>
<td><%= report.completed %></td>
<td><%= report.planned %></td>
<td><%= report.releases %></td>
<td><%= link_to 'Show', report %></td>
<td><%= link_to 'Edit', edit_report_path(report) %></td>
<td><%= link_to 'Destroy', report, :method => :delete, :data => { :confirm => 'Are you sure?' } %></td>
</tr>
<% end %>
<% end %>
</table>
/app/controllers/reports/showEntries.js.erb 内
var selectDate = $("#datepicker").val();
$("#displayReports").html("<%= escape_javascript(render(:partial => 'display', :locals => { :date => " + selectDate + " })).html_safe %>");
/config/routes.rb 内
Summary::Application.routes.draw do
resources :reports do
collection do
get 'weekly_email'
post 'showEntries'
end
end
get "home/index"
end
ページを実行しようとすると、次のエラーが表示されます。
No route matches {:action=>"showEntries", :remote=>"true", :controller=>"reports"}
この質問に似た多くの質問は、あまり役に立ちませんでした。私が間違っていることや、Rails AJAX 呼び出しに関するサイトを教えていただければ幸いです。ありがとう。<3