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?
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).
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"
.
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.
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.
精彩评论