2012-07-28 80 views
2

也有类似的问题,但我已经过去了,他们都没有应用。Rails,Devise Invitations 406 STI的不可接受的错误

我使用的是DeviseDevise invitations。 Rails 3.2.6。

棘手的是我有两个用户模型。用户和艺术家从用户继承的单个表继承设置。我有两个邀请控制器允许分别向用户和艺术家发送邀请。

现在的问题是艺术家无法接受他们的邀请。在表单提交更新密码后,他们得到了406个不可接受的错误。

相关代码:

路由:

devise_for :users, 
      :class_name => User, 
      :controllers => { :invitations => 'user/invitations' } 

    namespace :artist do 
    # Special route for devise, artists invitation 
    devise_scope :user do 
     resource :invitation, :controller => :invitations, :only => [:create, :new, :update] do 
     get :accept, :action => :edit 
     end 
    end 
    end 

艺术家邀请控制器

class Artist::InvitationsController < Devise::InvitationsController 
    respond_to :html 

    # PUT /resource/invitation 
    def update 
    self.resource = Artist.accept_invitation!(params[resource_name]) 

    if resource.errors.empty? 
     resource.pending 
     flash[:notice] = "Welcome, complete your artist agreement to get started" 
     sign_in(:user, resource) 
     respond_with resource, :location => after_accept_path_for(resource) 
    else 
     respond_with_navigational(resource){ render :edit } 
    end 
    end 
end 

形式描述。 edit.html.erb。

<%= form_for resource, :as => resource_name, :url => artist_invitation_path(resource_name), :html => { :method => :put } do |f| %> 
    <%= f.hidden_field :invitation_token %> 
    <%= f.label :password, class: 'control-label' %> 
    <%= f.password_field :password, :placeholder => 'Enter a password' %> 
    <%= f.label :password_confirmation, class: 'control-label' %> 
    <%= f.password_field :password_confirmation, :placeholder => 'Confirm your password' %> 
    <%= f.submit "Set my password", :'data-disable-with' => "Hang on..." %> 
<% end %> 

接受头

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3 
Accept-Encoding:gzip,deflate,sdch 
Accept-Language:en-US,en;q=0.8 
Cache-Control:max-age=0 
Connection:keep-alive 
Content-Length:236 
Content-Type:application/x-www-form-urlencoded 

返回

Request URL:http://localhost:3000/artist/invitation.user 
Request Method:POST 
Status Code:406 Not Acceptable 

我能看到的东西,格式必须是因为在对。用户最终将响应了。我不能为我的生活看到为什么或在哪里发生。请让我知道是否有任何信息我可以帮忙。

+1

我的猜测是'/ artist/invitation.user'来自你放入表单标签中的url字段。看看生成的表单html,看看是否是这种情况。如果是这样,尝试使用表单标记的选项来查看是否有帮助。 – Frost 2012-07-28 15:07:28

+0

谢谢。这导致我孤立了这个变量。 – ScotterC 2012-07-28 21:23:41

回答

1

明白了,最后。

关键是要精确地查看resource_name在整个窗体和控制器操作中所提供的内容。在我的情况下,它继续回退到:用户,当它需要:艺术家和弗罗斯特在评论中提到,生成的表单HTML会发生很大变化,如果你注意使用resource_name的位置。控制器中的更新操作需要被覆盖以直接使用:artist,并且需要调整form_for以从参数中删除resource_name,并使用:as参数。