在views/users/index.html.erb
我有:
<% @users.each do |user| %>
<% if user.teacher == current_user.teacher || current_user.role == "admin" %>
<tr>
<td><%= user.username %></td>
<td><%= user.email %></td>
<td><%= user.teacher %></td>
<td><%= user.role %></td>
<td><%= user.admin %></td>
<td><%= link_to 'Problems', student_problems_path(user_email: user.email) %></td>
<td><%= link_to 'Edit', edit_user_registration_path(user) %></td>
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
<% end %>
</table>
当您单击 时Edit
,您将链接到views/users/edit.html.erb
,如下所示:
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= form_for(resource, :as => resource_name, :url => 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, :autofocus => true %></div>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>
<div><%= f.submit "Update" %></div>
<% end %>
问题是,当我点击Update
并实际尝试更新模型时,我得到
Couldn't find User with id=edit
in app/controllers/users_controller.rb:51:in `update`
以下是 中的update
和edit
动作UsersController
:
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])
redirect_to(user_path)
end
而且,如果有帮助,这是我的路线:
root / problems#new
feedback_index POST /feedback(.:format) feedback#create
new_feedback GET /feedback/new(.:format) feedback#new
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
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
user_registration PUT /users(.:format) devise/registrations#update
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
problems GET /problems(.:format) problems#index
POST /problems(.:format) problems#create
new_problem GET /problems/new(.:format) problems#new
edit_problem GET /problems/:id/edit(.:format) problems#edit
problem GET /problems/:id(.:format) problems#show
PUT /problems/:id(.:format) problems#update
DELETE /problems/:id(.:format) problems#destroy
help_about GET /help/about(.:format) help#about
problems_new GET /problems/new(.:format) problems#new
data /data(.:format) problems#data
student_problems /student_problems(.:format) users#student_problems
感谢任何为我研究这个问题的人,它最近出现了很多。