问题:
我希望下拉列表列出用户的姓氏。怎么能做到这一点?
app/controllers/courses_controller
def edit
@course = Course.find(params[:id])
@teachers = User.where('teacher is true').order(:last_name).all
end
看法
= simple_form_for @course do |f|
- if @course.errors.any?
#error_explanation
%h2= "#{pluralize(@course.errors.count, "error")} prohibited this course from being saved:"
%ul
- @course.errors.full_messages.each do |msg|
%li= msg
.field
= f.input :name
.field
= f.input :password
.field
= f.input :description
- if @current_user
- if @current_user.admin?
= f.input :user, collection: @teachers
.actions
= f.submit 'Save', class: 'btn btn-primary'