我对 Rails 很陌生,我在 posts_controller.rb 中创建了一个方法,其中包含以下内容
def update_feeds
Post.get_feeds -- works via console
@rss_feedsTab = "/admin/posts"
redirect_to @rss_feedsTab, :notice => 'Feeds Updated successfully'
end
并试图通过以下方式使其在我看来着火:
<%= link_to 'Update Feeds', :controller => "posts", :action => "update_feeds", :method=>:post %>
我得到一个路由错误:
No route matches {:action=>"update_feeds", :method=>:post, :controller=>"admin/posts"}
我真的不明白整个路由是如何工作的,任何帮助将不胜感激:)
CONTROLLER=发布 rake 路线:
admin_post GET /admin/posts/:id(.:format) admin/posts#show
PUT /admin/posts/:id(.:format) admin/posts#update
DELETE /admin/posts/:id(.:format) admin/posts#destroy
GET /admin/posts(.:format) admin/posts#index {:collection=>{:update_feeds=>:post}}
POST /admin/posts(.:format) admin/posts#create {:collection=>{:update_feeds=>:post}}
GET /admin/posts/new(.:format) admin/posts#new {:collection=>{:update_feeds=>:post}}
GET /admin/posts/:id/edit(.:format) admin/posts#edit {:collection=>{:update_feeds=>:post}}
GET /admin/posts/:id(.:format) admin/posts#show {:collection=>{:update_feeds=>:post}}
PUT /admin/posts/:id(.:format) admin/posts#update {:collection=>{:update_feeds=>:post}}
DELETE /admin/posts/:id(.:format) admin/posts#destroy {:collection=>{:update_feeds=>:post}}
路线.rb
namespace :admin do
resources :users,:videos,:posts,:links,:rss_feeds
resources :posts, :collection => {:update_feeds => :post}
end