簡體   English   中英

CRUD index.html.erb,new.html.erb,編輯等頁面未顯示? Ruby 上軌

[英]CRUD index.html.erb, new.html.erb, edit, etc pages not showing? Ruby On Rails

目前我的 index.html、new.html.erb 等文件中沒有任何內容正在加載。 例如,如果我輸入 http://localhost:3000/teams/new 或 http://localhost:3000/teams,除了我的導航欄加載之外什么都沒有。

這是我的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”這樣的虛擬文本,但即使這樣也沒有渲染。 任何幫助,將不勝感激!

看起來您已經從application.html.erb文件中刪除了yield <%= render:partial => "partials/nav" %> <%= yield %> > 。

<%= yield %>將呈現當前控制器#action 的模板。

您可以在此處閱讀有關產量的更多信息。

您尚未在布局文件中添加yield ,即application.html.erb您應該在正文或_nav.html.erb中添加<%= yield %> ,具體取決於您的頁面樣式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM