Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在概览/索引中使用日期选择器的最佳实践_Ruby On Rails_Ruby_Select_Get_Indexing - Fatal编程技术网

Ruby on rails 在概览/索引中使用日期选择器的最佳实践

Ruby on rails 在概览/索引中使用日期选择器的最佳实践,ruby-on-rails,ruby,select,get,indexing,Ruby On Rails,Ruby,Select,Get,Indexing,我是rails新手,尝试了解使用会议控制器中的索引方法创建的会议列表的概述。该页面还具有“选择所有年份”功能,因此您可以选择特定年份,以便仅查看所选年份的会议。我意识到在页面上添加了一个表单: index.html.erb: <h1>Protokolle</h1> <%= form_tag 'meetings', :method => :get do %> <%= select_tag :selected_year, options_for_se

我是rails新手,尝试了解使用会议控制器中的索引方法创建的会议列表的概述。该页面还具有“选择所有年份”功能,因此您可以选择特定年份,以便仅查看所选年份的会议。我意识到在页面上添加了一个表单:

index.html.erb:

<h1>Protokolle</h1>
<%= form_tag  'meetings', :method => :get do %>
<%= select_tag :selected_year, options_for_select(available_years, @year), {onchange: 'this.form.submit();'}   %>
<% end  %>
<%= link_to image_tag('new'), new_meeting_path %>
...
使用put作为表单的动作方法,不起作用,但get看起来很难看

如何才能做得更好

财务主任会议:

class MeetingsController < ApplicationController

def index
  @year = selected_year(params[:selected_year])
  @meetings = Meeting.where(:held_on => ("01.01.#{@year}".to_date)..("31.12.#{@year}".to_date)).order('held_on desc').all

  respond_to do |format|
    format.html # index.html.erb
  end
end
...

感谢您的提示…

在表单中使用GET进行GET-only操作没有问题。PUT不起作用,因为RESTful路由-POST版本将激活“会议”路由,并为新会议调用“创建”,PUT被路由器简单地拒绝为不存在。

感谢您的评论。对我来说,使用表单似乎不太好,也许使用ajax可以做得更好。ajax会有什么不同?它仍然是一个get请求,只是以其他方式调用。您希望它在视觉上看起来怎么样?也许我们可以从那里建起来?