使用带有link_to的帖子

时间:2011-04-27 22:39:08

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

我有这条路线:

avatar_add_from_collection POST   /avatars/:avatar_id/add_from_collection(.:format)            {:action=>"add_from_collection", :controller=>"avatars"}

我正在尝试使用使用post的link_to创建链接。我需要这样做的原因是因为(显然)你不能使用button_to将图像放在按钮上。

<%= link_to inline_avatar(avatar.fetch_avatar_image(:thumb)), add_from_collection_avatar_path(avatar),:method=>:post%>

提出

No route matches "/avatars/3/add_from_collection"

如果我更改路线文件以使其成为GET,它就可以正常工作。

link_to看起来像

link_to inline_avatar(avatar.fetch_avatar_image(:thumb)), avatar_add_from_collection_path(avatar),:method=>:post

编辑:

Jade::Application.routes.draw do

  resources :avatar_categories do
    delete :remove_item
  end

  resources :avatars do
    member do
     post 'add_from_collection', :on=>:member
    end
  end

  resources :categories,:addresses,:calendars,:topics,:profile,:news,:account_setting
  resources :boards do
    member do
      get :move
      post :move_category
    end
  end

  post 'avatars/display_collection'
  get "user/index"
  get 'login/index'
  get 'login/new'
  post 'login/create'
  post 'login/authenticate'
  get 'login/forgot_password'
  put 'login/reset_password'
  get 'login/logout' #post?
  get 'admin/index'
  get 'admin/app_settings'
  get 'admin/user_settings'
  get 'admin/avatars'
  post 'admin/avatar_upload'
  post 'admin/update_app_settings'
  get 'news_configurations/index'
  put 'news_configurations/update'
  get 'message_board_configurations/index'
  put 'message_board_configurations/update'
  get 'profile_settings/edit'
  post 'profile_settings/update'

  resources :posts do
    get :new,:edit
    post :create,:update,:destroy
  end

  match '/login' => 'login#index', :as => 'login'
  match '/admin' => 'admin#index', :as => 'admin'

  resources :login do
    get :index
    post :authenticate,:logout
  end
root :to => "news#index"

end

1 个答案:

答案 0 :(得分:0)

resources :avatars do 
  member do
    post 'add_from_collection'
  end
end

resources :avatars do 
  post 'add_from_collection', :on => :member
end

修改

这是错误的

resources :avatars do
  member do
   post 'add_from_collection', :on=>:member
  end
end

使用此

resources :avatars do
  post :add_from_collection, :on=>:member
end

但看起来这样做无济于事