简体   繁体   English

Ruby on Rails 3路线问题

[英]Ruby on Rails 3 Routes Question

When clicked on the link below, it takes me to the show screen, instead of deleting the thing. 单击下面的链接时,它将带我到显示屏幕,而不是删除该内容。

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

Controller 控制者

  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

Something must be wrong in my routes. 我的路线上一定有问题。 can someone help me find the error? 有人可以帮助我找到错误吗?

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

Can someone explain where I went wrong? 有人可以解释我哪里出问题了吗? Thanks. 谢谢。

Are you using the Rails Unobtrusive JavaScript (UJS) drivers for Prototype of jQuery? 您是否正在将Rails Unobtrusive JavaScript(UJS)驱动程序用于jQuery原型?

In Rails 2.3 the :delete method would setup some JS in the link to send the request as a form post using the delete 'method' (via the _method param). 在Rails 2.3中,:delete方法将在链接中设置一些JS,以使用删除“方法”(通过_method参数)将请求作为表单发布发送。

Now in Rails 3 the inline JS has been removed (thank goodness!) and you will notice that the link has a few new attributes, namely data-method="delete" and, if you are using the confirm option, data-confirm="Your confirmation message" . 现在,在Rails 3中,内联JS已被删除(谢天谢地!),您会注意到该链接具有一些新属性,即data-method="delete" ;如果使用Confirm选项,则data-confirm="Your confirmation message"

The Rails UJS driver, when the page is loaded, looks for any links etc with these attributes and attaches events to them, which then does the same as what the inline javascript would have done. 加载页面后,Rails UJS驱动程序会查找具有这些属性的任何链接等并将事件附加到它们,然后执行与内联JavaScript相同的操作。

If you are using Prototype you can find the UJS file at http://github.com/rails/prototype-ujs , and jQuery at http://github.com/rails/jquery-ujs - just make sure this file is loaded after the JS framework, and before your application.js file. 如果您使用的原型,你可以找到在UJS文件http://github.com/rails/prototype-ujs在和jQuery http://github.com/rails/jquery-ujs -只要确保这个文件被加载 JS框架之后, application.js文件之前

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM