可能很简单的路由错误:没有路由匹配{:action

时间:2011-11-21 22:04:55

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1

我认为我的创建方法有问题。

当我从http://localhost:3000/http://localhost:3000/resumes/new创建新简历时,我收到如下所示的路由错误。


Routing Error
No route matches {:action=>"show", :controller=>"resumes"}

应用转到http://localhost:3000/resumes地址而不是http://localhost:3000/resumes/1。不知道为什么。

这是我的代码。

class SubmissionsController < ApplicationController
def create
  @resume = Resume.new(params[:resume])
  if @resume.save
    #UserMailer.created_resume_email(@user).deliver
    redirect_to :action => 'show'
    format.html { redirect_to(@resume, :notice => 'Resume was successfully created.') }
    format.xml  { render :xml => @resume, :status => :created, :location => @resume }
  else
    @title = "Create a new resume"
    render 'new'
  end
end

def show
  @resume = Resume.find(params[:id])
  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @resume }
  end
end
end

Leaflet::Application.routes.draw do
  resources :resumes
  match '/' => 'resumes#new'
end

1 个答案:

答案 0 :(得分:1)

我可能遗漏了一些东西,但是,我相信你需要改变你的redirect_to语句。

redirect_to resume_url(@resume)

redirect_to resume_path(@resume)

这应该将用户重定向到控制器中的“show”操作,并使用所需的参数来确定要获取和显示的简历。

http://guides.rubyonrails.org/layouts_and_rendering.html#using-redirect_to