非CRUD轨道布线



我构建了以下控制器和路由。我希望表单发布到路径,例如/production/:date,但我得到的是

http://localhost:3000/production/update_week?utf8=✓&date=2015-02-17&commit=Update

控制器

def index
    @date = session[:week] ||= Date.current
  end
  def show
    @date = params[:date]
    respond_to do |format|
      format.html  
    end
  end
  def update_week
    session[:week] = params[:date]
    respond_to do |format|
      format.html { redirect_to week_path(session[:week]) }
    end
  end

表单

%p.field
  = form_tag update_week_path, method: :get do
    = label_tag "Week of:"
    = text_field_tag :date, @date, id: 'datepicker'
    = submit_tag "Update"

路由

  get 'production/:date' => 'production#show', as: :week
  get 'production' => 'production#index', as: :production
  get 'production/update_week' => 'production#update_week', as: :update_week

在这一行中,您指定要使用的路径:

= form_tag update_week_path, method: :get do

在你的路线中,update_week_path是这条线:

get 'production/update_week' => 'production#update_week', as: :update_week

如果你想让它去production/:date,你需要使用这个路线:

get 'production/:date' => 'production#show', as: :week

像这样:

= form_tag week_path(your_date_goes_here), method: :get do

最新更新