CRUD index. html .erb, new. html .erb, edit, et c страницы не отображаются? Ruby На рельсах - PullRequest
0 голосов
/ 09 июля 2020

в настоящее время ничего из моего индекса. html, новые. html .erb, et c файлы загружаются. Например, если я наберу http://localhost: 3000 / team / new или http://localhost: 3000 / team, ничего, кроме моей панели навигации, не загрузится.

Вот мой teams_controller.rb

class TeamsController < ApplicationController
  before_action :set_team, only: [:show, :edit, :update, :destroy]

  # GET /teams
  # GET /teams.json
  def index
    @teams = Team.all.sort_by {|t| t.total_points}
  end

  # GET /teams/1
  # GET /teams/1.json
  def show
    @team_roster = User.for_team(@team).by_first_name
  end

  # GET /teams/new
  def new
    @team = Team.new
  end

  # GET /teams/1/edit
  def edit
  end

  # POST /teams
  # POST /teams.json
  def create
    @team = Team.new(team_params)

    respond_to do |format|
      if @team.save
        format.html { redirect_to @team, notice: 'Team was successfully created.' }
        format.json { render :show, status: :created, location: @team }
      else
        format.html { render :new }
        format.json { render json: @team.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /teams/1
  # PATCH/PUT /teams/1.json
  def update
    respond_to do |format|
      if @team.update(team_params)
        format.html { redirect_to @team, notice: 'Team was successfully updated.' }
        format.json { render :show, status: :ok, location: @team }
      else
        format.html { render :edit }
        format.json { render json: @team.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /teams/1
  # DELETE /teams/1.json
  def destroy
    if @team.destroy
      flash[:notice] = "Successfully removed #{@team.name}."
      redirect_to teams_url
    else
      @team_roster = User.for_team(@team.id).by_first_name
      render action: 'show'
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_team
      @team = Team.find(params[:id])
    end

    # Only allow a list of trusted parameters through.
    def team_params
      params.require(:team).permit(:name, :description, :active)
    end
end

А вот мой application.html.erb

<!DOCTYPE html>
<html>
  <head>
    <title>ACFQuarantineChallenge</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <%= csrf_meta_tags %>
    
    <%= csp_meta_tag %>



    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
  </head>

  <body>
  <%= render :partial => "partials/nav" %>
  </body>
</html>

А вот фрагмент index.html.erb

<% if @teams.empty? %>
  <h4>There are no teams in the system at this time.</h4>
<% else %>

  <h1>Teams</h1>

  <table>
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
        <th>Active</th>
        <th colspan="3"></th>
      </tr>
    </thead>

    <tbody>
      <% @teams.each do |team| %>
        <tr>
          <td><%= team.name %></td>
          <td><%= team.description %></td>
          <td><%= team.active %></td>
          <td><%= link_to 'Show', team %></td>
          <td><%= link_to 'Edit', edit_team_path(team) %></td>
          <td><%= link_to 'Destroy', team, method: :delete, data: { confirm: 'Are you sure?' } %></td>
        </tr>
      <% end %>
    </tbody>
  </table>

  <br>

  <%= link_to 'New Team', new_team_path %>

<%end%>

моей команды. Я уже пробовал вставить фиктивный текст вроде «Hello World» но даже это не было рендерингом. Любая помощь приветствуется!

Ответы [ 2 ]

2 голосов
/ 09 июля 2020

Похоже, вы удалили yield из своего application.html.erb файла. Добавьте <%= yield %> после <%= render :partial => "partials/nav" %>.

<%= yield %> отобразит шаблон текущего действия контроллера #.

Подробнее о yield можно узнать здесь .

1 голос
/ 09 июля 2020

Вы не добавили yield в свой файл макета, т.е. application.html.erb Вы должны добавить <%= yield %> в теле или _nav.html.erb в зависимости от стиля вашей страницы.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...