我更新方法有以下問題。Update_method不起作用
這裏是我的代碼:
def edit
@work_package = WorkPackage.find(params[:package])
unless current_user.admin? || own_project?(@project)
flash[:danger] = I18n.t('messages.errors.no_admin_rights_for_site')
redirect_to projects_path
return
end
end
def update
@work_package = WorkPackage.find(params[:id])
if @work_package.update_attributes(filter_update_work_package_params)
flash[:success] = updated_success_message(I18n.t('objects.work_package'))
redirect_to project_path(@work_package.project_id)
else
@object = @work_package
render 'edit'
end
end
這我work_package PARAMS
private
def filter_work_package_params
params.require(:work_package).permit(:name, :parent_id, :project_id, :started_on, :finished_on)
end
def filter_update_work_package_params
params.permit(:package_id, :project_id, :team_id, :person_month, :started_on, :finished_on)
end
當我點擊提交,什麼都沒有發生
這裏是控制檯日誌:
Started PATCH "/work_packages/33" for ::1 at 2015-11-06 09:14:49 +0100
Processing by WorkPackagesController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"R6k9B20nfUj4BSRDcA9+D+V73ihR9l9AzjFtBIoDYFGhxCkO+WsqOQzWhG7NCprxcQ3juJahH46ftHB94b3YNg==", "work_package"=>{"name"=>"Faraz", "parent_id"=>"", "project_id"=>"6", "started_on"=>"05.11.2015", "finished_on"=>"12.12.2015"}, "commit"=>"Absenden", "id"=>"33"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 2]]
Project Load (0.3ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 LIMIT 1 [["id", 6]]
WorkPackage Load (0.3ms) SELECT "work_packages".* FROM "work_packages" WHERE "work_packages"."id" = $1 LIMIT 1 [["id", 33]]
Unpermitted parameters: utf8, _method, authenticity_token, work_package, commit, id
(0.1ms) BEGIN
(0.1ms) COMMIT
Redirected to http://localhost:3000/projects/6
Completed 302 Found in 6ms (ActiveRecord: 0.9ms)
你有什麼想法嗎?
嘗試使用'filter_work_package_params'的'更新'方法。 – Pavan