0
基本上,我希望用戶能夠從5個不同的下拉菜單,稍後將在用戶的顯示頁面上查看選擇他們的前5名技能環路選擇下拉菜單5倍
用戶控制器:
class UsersController < ApplicationController
def new
@user = User.new
end
def show
@user = User.find(params[:id])
@events = @user.events
end
def create
@user = User.new(user_params)
if @user.save
session[:user_id] = @user.id
redirect_to root_url
else
render "new"
end
end
def edit
@user = current_user
end
def update
@user = current_user
@user.update_attributes(user_params)
if @user.save
redirect_to user_path(current_user)
else
render "edit"
end
end
def upload
uploaded_io = params[:user][:picture]
File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'wb') do |file|
file.write(uploaded_io.read)
end
end
private
def user_params
params.require(:user).permit(:email, :password, :password_confirmation, :first_name, :last_name, :region, :volunteer_position, :summary, :date_of_birth, :picture, :hours, :org_admin, :skills, :goals)
end
end
users model:
SKILLS = ["","Administrative", "Analytical", "Artistic/Creative", "Budgeting",
"Communicaton", "Computer", "Conflict Resolution", "Creating Ideas",
"Creating Procedures", "Creating New Solutions", "Customer Service",
"Decision Making", "Fundraising", "Handling Complaints", "Innovative",
"Leadership", "Learning", "Logical Thinking", "Maintaining High Levels of Activity",
"Negotiating", "Networking", "Organizational", "Planning", "Problem Solving",
"Reporting", "Team Work", "Technical", "Time Management", "Training"]
def select_skills
@skills = []
5.times do |i|
return i.skills
end
end
用戶show.html.erb
<tr>
<td>skills:</td>
<td><%= current_user.skills %></td>
</tr>
edit.html.erb
<tr>
<td> User Goals </td>
<% select User::SKILLS.each do |skill|%>
<% @skill = Skills.order.first(5) %>
<tr>
<th><%= current_user.skills %></th>
</tr>
<% end %>
錯誤消息:在用戶#編輯
引發ArgumentError
錯誤的參數數目(1給出,預期2..5)
您能夠發佈完整的錯誤消息,並且還你的模型,視圖和控制器和應用程序目錄結構中的每個文件的位置?我可能是錯的,但我會期待你寫的方法在控制器 – 2017-03-17 17:08:16
@RailsKiddie更新它! – Amena