Ruby on Rails 3路由问题

时间:2010-09-22 02:49:55

标签: ruby-on-rails routes

当点击下面的链接时,它会转到显示屏幕,而不是删除该内容。

      <th><%= link_to 'Destroy', blog, :method => :delete %></th>

控制器

  def destroy
    @blog = Blog.find(params[:id])
    @blog.destroy

    respond_to do |format|
      format.html { redirect_to(root_path) }
      format.xml  { head :ok }
    end
  end

我的路线肯定有问题。有人可以帮我找到错误吗?

PremSite::Application.routes.draw do
  resources :blogs

  resources :portfolios do
    member do
      get 'show_port'
    end
  end

  get "admin/index"

  resources :rosters

  #All the static service pages

  match "bloggers" => 'dashboard#bloggers'

  match "sitemap" => 'dashboard#sitemap'
  match "about" => 'dashboard#about'
  match "about_team" => 'dashboard#about_team'
  match "service" => 'dashboard#service'
  match "portfolio" => 'dashboard#portfolio', :as => 'view'
  match "contact" => 'dashboard#contact'
  match "blogger" => 'dashboard#blogger'
  match "admin" => 'admin#index'

  match "services/web_development" => 'services#web_development'
  match "services/design_brand" => 'services#design_brand'
  match "services/flash_solutions" => 'services#flash_solutions'
  match "services/ecommerce" => 'services#ecommerce'
  match "services/emarket" => 'services#emarket'
  match "services/applications" => 'services#applications'
  match "services/seo_solutions" => 'services#seo_solutions'
  match "services/google_adwords" => 'services#google_adwords'
  match "services/google_analytics" => 'services#google_analytics'
  match "services/website_evaluation" => 'services#website_evaluation'
  match "newsletter/join" => 'newsletter#join'

  root :to=> "dashboard#index"
end

有人可以解释我哪里出错吗?感谢。

1 个答案:

答案 0 :(得分:1)

你是否正在使用Rails Unobtrusive JavaScript(UJS)驱动程序用于jQuery的Prototype?

在Rails 2.3中:delete方法会在链接中设置一些JS,使用delete'方法'(通过_method参数)将请求作为表单发送。

现在在Rails 3中,内联JS已被删除(谢天谢地!),您会注意到该链接有一些新属性,即data-method="delete",如果您使用的是确认选项,{{1 }}

当加载页面时,Rails UJS驱动程序会查找具有这些属性的任何链接等,并将事件附加到它们,然后执行与内联javascript相同的操作。

如果你正在使用Prototype,你可以在http://github.com/rails/prototype-ujs找到UJS文件,在http://github.com/rails/jquery-ujs找到jQuery - 只需确保在 JS框架之后加载这个文件,并且之前你的application.js文件。