0

我有以下 form_for 标签,配置文件带有它正在生成的 URL,它是无效的,即这里是标签:

<%= form_for([current_user,@profile], :html =>{:class => "contact_form",:multipart => true}) do |f| %>

预测这个“action="/users/1/profile.1" 应该是 action="/users/1/profile/1"

谁能看到我在这里做错了什么?

下面是来自相关 Rails 文件的一些快照。

路线.rb

devise_for :users
resources :users, :only => [:delete] do
  resource :profile
end

用户模型

class User < ActiveRecord::Base
  has_one :profile, :inverse_of => :user
  accepts_nested_attributes_for :profile

轮廓模型

class Profile < ActiveRecord::Base
  belongs_to :user
  validates_presence_of :user

耙路线输出:

new_user_session GET    /users/sign_in(.:format)               devise/sessions#new
            user_session POST   /users/sign_in(.:format)               devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)              devise/sessions#destroy
           user_password POST   /users/password(.:format)              devise/passwords#create
       new_user_password GET    /users/password/new(.:format)          devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)         devise/passwords#edit
                         PUT    /users/password(.:format)              devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)                devise/registrations#cancel
       user_registration POST   /users(.:format)                       devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)               devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)                  devise/registrations#edit
                         PUT    /users(.:format)                       devise/registrations#update
                         DELETE /users(.:format)                       devise/registrations#destroy
            user_profile POST   /users/:user_id/profile(.:format)      profiles#create
        new_user_profile GET    /users/:user_id/profile/new(.:format)  profiles#new
       edit_user_profile GET    /users/:user_id/profile/edit(.:format) profiles#edit
                         GET    /users/:user_id/profile(.:format)      profiles#show
                         PUT    /users/:user_id/profile(.:format)      profiles#update
                         DELETE /users/:user_id/profile(.:format)      profiles#destroy
4

1 回答 1

0

i had the same problem. my solution was, that you have to declare the url directly like this:

<%= form_for([current_user,@profile], :url => user_profile_path, :html =>{:class => "contact_form",:multipart => true}) do |f| %>

although i don't really know why this thing occurs - perhaps anyone could explain...

于 2012-04-08T19:43:16.733 回答