userとprojectとその中間テーブルのuser_projectがあります。
userカラムの中にdegree_of_reliabilityという数字(integer)があるのですが、「参加者を評価する」というボタンを押すとその数字が1上がるというコードを書きたいのですがうまくいきません。
わかる人がいましたら教えていただきたいです。
実際のコード
routes.rb
Rails.application.routes.draw do devise_for :users root to: "top#index" resources :users, only: [:show, :edit, :update] resources :project, only: [:new, :create, :show] do resources :join, only: [:create] resources :degree_of_reliability, only: [:update] end end
project_comtroller.rb
class ProjectController < ApplicationController def new @project = Project.new end def create @projectcreate = Project.create(project_params) UserProject.create(user_id: current_user.id, project_id: @projectcreate.id) end def show @project = Project.find(params[:id]) @projects = Project.all.order("id DESC") end private def project_params params.require(:project).permit(:title, :details, :photo, :required_reliability).merge(user_id: current_user.id, organizer: current_user.name) end end
degree_of_reliability_comtroller.rb
class RequiredReliabilityController < ApplicationController def edit @project = Project.find(params[:project_id]) participant = @project.user.id @user = User.where(id: params[:participant]) new_reliability = @user.degree_of_reliability + 1 @user.update(degree_of_reliability: new_reliability) end end
project/show.html.erb
<div class="row"> <中略> <div class=""> <p class="btn white"><%= link_to "参加者を評価する", project_degree_of_reliability_path %></p> </div> </div>
degree_of_reliability/update.html.erb
<div> <p>評価しました</p> <a class="btn" href="/">ホームに戻る</a> </div>
エラー画面
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。