表单自动呈现创建操作

时间:2015-06-02 20:39:45

标签: ruby-on-rails ruby controller

我的索引页面加载正常。我在视图中有这个:

<%= form_tag('tickets') do %>
  <%= select_tag 'Filter', options_from_collection_for_select(User.all, 'id', 'full_name'), include_blank: true, class: 'form-control' %>
  <%= submit_tag 'Filter', class: "btn btn-default" %>
<% end %>

这是控制器:

def index
  tickets = Ticket.all
  @tickets_by_date = tickets.group_by(&:start_date)
  @date = params[:date] ? Date.parse(params[:date]) : Date.today
end

def create
  @ticket = Ticket.new(ticket_params)
  if @ticket.save
    redirect_to tickets_path
  else
    render 'tickets/new'
  end
end

def ticket_params
  params.require(:ticket).permit(:name, :summary, :creator_id, :start_date, :end_date, :customer_id, :status_id, :priority_id, :type_id, :assignee_id)
end

当我点击索引字段上的过滤器表单提交时,我收到此错误:

ActionController::ParameterMissing in TicketsController#create

param is missing or the value is empty: ticket

这是在索引页面上呈现的html:

<form action="tickets" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓"><input type="hidden" name="authenticity_token" value="4RUirKnLeJrEVFLfICuHmiNWr7gkUw9ehHPExsOXS8lYlmRl4bFIstHosRFIedtQie2pLxrOVG1ZBM+ksNQvqA==">
  <select name="Filter" id="Filter" class="form-control">
    <option value=""></option>
    <option value="1">Cameron Aziz</option>
  </select>
  <input type="submit" name="commit" value="Filter" class="btn btn-default">
</form>

为什么要调用创建控制器?如何修复它以便它基本上重新呈现#index操作页面?

0 个答案:

没有答案