2013-05-01 1 views
0

레일즈 3과 디비 이스를 인증에 사용하고 있습니다. 내 current_user를 업데이트하려고하면 예외가 진술 발생합니다 :레일즈 - id = edit를 가진 사용자를 찾을 수 없습니다.

Couldn't find User with id=edit 
app/controllers/users_controller.rb:49:in `update' 

여기 UsersController에서 updateedit입니다 :

#UsersController.rb 
def update 
    @user = User.find(params[:id]) 

    respond_to do |format| 
     if @user.update_attributes(params[:user]) 
     format.html { redirect_to @user, notice: 'User was successfully updated.' } 
     format.json { head :no_content } 
     else 
     format.html { render action: "edit" } 
     format.json { render json: @user.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

def edit 
    @user = User.find(params[:id]) 
end 

을 그리고 여기 /views/layouts/_navigation.html.erb입니다 : 마지막으로

<%= link_to "Home", root_path, :class => 'brand' %> 
<ul class="nav"> 
    <% if user_signed_in? %> 
    <li> 
    <%= link_to('Logout', destroy_user_session_path, :method=>'delete') %> 
    </li> 
    <% else %> 
    <li> 
    <%= link_to('Login', new_user_session_path) %> 
    </li> 
    <% end %> 
    <li> 
    <%= link_to('About', help_about_path) %> 
    </li> 
    <% if user_signed_in? %> 
    <li> 
    <%= link_to('Edit Account', edit_user_path(current_user)) %> 
    </li> 
    <% end %> 
    <% if user_signed_in? and current_user.role == "gen_admin" || current_user.role == "teacher" %> 
    <li> 
    <%= link_to('View Students', users_path) %> 
    </li> 
    <% end %> 
    <% if user_signed_in? and current_user.role == "gen_admin" || current_user.role == "teacher" %> 
    <li> 
    <%= link_to('New User', new_user_path) %> 
    </li> 
    <% end %> 
    <% if user_signed_in? %> 
    <li> 
    <%= link_to('Student Data', data_path) %> 
    </li> 
    <% end %> 
</ul> 

, 여기에 /views/devise/registrations/edit.html.erb :

<h2>Edit <%= resource_name.to_s.humanize %></h2> 

<%= form_for(resource, :as => resource_name, :url => edit_user_registration_path(resource_name), :html => { :method => :put }) do |f| %> 
    <%= devise_error_messages! %> 

    <div><%= f.label :email %><br /> 
    <%= f.email_field :email, :autofocus => true %></div> 

    <div><%= f.label :teacher %><br /> 
    <%= f.text_field :teacher %></div> 

    <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> 
    <div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div> 
    <% end %> 

    <div><%= f.label :new_password %> <i>(leave blank if you don't want to change it)</i><br /> 
    <%= f.password_field :password, :autocomplete => "off" %></div> 

    <div><%= f.label :password_confirmation %><br /> 
    <%= f.password_field :password_confirmation %></div> 

    <div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br /> 
    <%= f.password_field :current_password %></div> 

    <div><%= f.submit "Update" %></div> 
<% end %> 

<%= link_to "Back", :back %> 

왜 사용자 ID가 편집입니까? 그 도움이된다면 여기 내 해시입니다 :

{"utf8"=>"✓", 
"_method"=>"put", 
"authenticity_token"=>"7g1WsNCVuNY/5ZTeBUdv97tbdAPacvvDAzBSMGCcuNY=", 
"user"=>{"email"=>"[email protected]", 
"teacher"=>"Demont", 
"password"=>"[FILTERED]", 
"password_confirmation"=>"[FILTERED]", 
"current_password"=>"[FILTERED]"}, 
"commit"=>"Update", 
"id"=>"edit", 
"format"=>"user"} 
+0

편집 작업 코드를 게시 할 수 있습니까? –

+0

'edit' 액션을 추가했습니다. 여기서 아주 늦었 기 때문에 아침마다 여기에있는 모든 사람들의 반응을 사용하여이 문제를 해결하고 저에게 가장 잘 맞는 답을 표시하려고 노력할 것입니다. 모두에게 감사드립니다! – Houdini

답변

1

대신 "편집"을 가지고 이유. ... 자신의 위키 페이지에서 같은 양식을 사용하여 https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-password

을 시도하지만, 위의 코드는 폼보기로이

+0

아마도 내 경로에 큰 문제가있을 수 있습니다. 그러나'params [: id] '대신에'current_user'를 사용하는 것이 저에게는 효과적입니다. 다른 사람들 덕분에, 나는 그것들이 유효한 대답이기도하다는 것을 확신합니다. – Houdini

1

대부분의 당신 가능성이 UsersController을 추가 할 때 나는 당신의 경로에 충돌을 가지고있다.

설명하는 것은 devise's wiki page입니다.

편집 사용자의 기본 장치 경로는 /users/edit이지만 컨트롤러 경로에서 업데이트 작업은 /users/:id입니다.

@user = current_user 

뭔가 경로 또는 편집 양식을 잘못 보인다 : 어떻게 당신이 사용해보십시오 user_id

0

사용

<%= form_for(@resource, :as => resource_name, :url => edit_user_registration_path(resource_name), :html => { :method => :put }) do |f| %> 

극복해야하며,

@resource = User.find(params[:id]) 

편집 작업에서

관련 문제