开发者

best practice for using a date selector in an overview/index

I am new to rails and try to realise a overview of a list of meetings created using the index method in the meeting controller. The page has also a select with all years, so that you can select a specific year to see only the meetings of the selected year. I realized it adding a form on the page:

ind开发者_如何学运维ex.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 %>
...

Using put as the action method of the form, does not work, but get seems to be ugly.

How can this be done better?

meetings_controller:

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
...

Thanks for your tips ...


There's no problem using GET in a form for a get-only action. PUT doesn't work, because of RESTful routes - the POST version would activate the 'meetings' route will call 'create' for a new meeting, PUT is simply denied by the router as not existing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜