lundi 13 janvier 2020

how can i render form from other controller using link_to in rails?

Hi have project scaffold and that had project list. i have created stage scaffold with some field. now i want to render stage form in show page of project view. i tried but i am getting error. i want to use a link_to in show page of the project show to the form of the stage.

routes.rb

Rails.application.routes.draw do
  resources :stages
  resources :projects
end

projects show.html.erb

<p id="notice"><%= notice %></p>

<p>
  <strong>Project name:</strong>
  <%= @project.project_name %>
</p>
<%= link_to 'Edit', edit_project_path(@project) %> |
<%= link_to 'Back', project_managers_path %>

<br>
<br>
<%= link_to "Add Stage", stage_form_path %>

project_controller.rb

  def index
    @projects = current_user.projects.all.paginate(page: params[:page], per_page: 15)
  end


  def show
    @stages = Stage.new
  end

each project has many stages relation in model.

Aucun commentaire:

Enregistrer un commentaire