我认为这是:
<% @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) %></td>
<td><%= link_to 'Edit', edit_user_path(user) %></td>
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
<% end %>
所以,我user
作为参数传递给student_problems_path
. 在我的UsersController
我有:
def student_problems
@problems = Problem.all
@user = user.email
end
但是,Rails 告诉我以下内容:
undefined local variable or method `user' for #<UsersController:0x3d79208
如何访问从视图user
传递给的变量?UsersController
谢谢!
编辑
这是我的路线:
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#ed
user_registration PUT /users(.:format) devise/registrations#up
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
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
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