Я создал проект эшафот и сцену в рельсах. у обоих есть много к одному объединению в рельсах. Как каждый проект будет иметь несколько этапов, и пользователь будет иметь несколько проектов. Я могу сделать проект будет связанный идентификатор пользователя, но этап отображается для каждого пользователя. я могу решить эту проблему?
project.rb
has_many :stages
stage.rb
belongs_to :project
project show. html .erb, где я отображаю этап проекта
<div class="table-scroll">
<table>
<thead>
<tr>
<th>Stage</th>
<th>Responsibility</th>
<th>Status</th>
<th>Finance</th>
</tr>
</thead>
<tbody>
<% @stages.each do |stage| %>
<tr>
<td><%= stage.stage %></td>
<td><%= stage.responsibility %></td>
<% if stage.status == true %>
<td class="completed"><%= "Completed" %></td>
<% elsif stage.status == false %>
<td class="in-progress"><%= "In-Progress" %></td>
<% else %>
<td class="yet-to-start"><%= "Yet to Start" %></td>
<% end %>
<td><%= stage.finance %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
projects_controller.rb
def index
@projects = current_user.projects.all.paginate(page: params[:page], per_page: 15)
end
def show
@project=Project.find(params[:id])
@stages = Stage.all
end
def new
@project = current_user.projects.build
end
def create
@project = current_user.projects.build(project_params)
respond_to do |format|
if @project.save
format.html { redirect_to @project, notice: 'Project was successfully created.' }
format.json { render :show, status: :created, location: @project }
else
format.html { render :new }
format.json { render json: @project.errors, status: :unprocessable_entity }
end
end
end
stage_controller.rb
def index
@stages = Stage.all
end
def show
end
def new
@stage = Stage.new
@project = Project.find(params[:project_id])
end
def create
@project = Project.find(params[:project_id])
@stage = @project.stages.build(stage_params)
respond_to do |format|
if @stage.save
format.html { redirect_to project_stages_path, notice: 'Stage was successfully created.' }
format.json { render :show, status: :created, location: @stage }
else
format.html { render :new }
format.json { render json: @stage.errors, status: :unprocessable_entity }
end
end
end
Я хочу, чтобы stage отображался только в связанном проекте. какие изменения мне нужно сделать?