嵌入式ruby没有出现在网页上

时间:2017-09-27 16:38:50

标签: html ruby

我试图为播客网站创建新的剧集表单,当我尝试重新加载页面时没有任何反应,我收到错误:

Started GET "/podcasts/1/episodes/new" for 127.0.0.1 at 2017-09-27 09:33:27 -0700
Processing by EpisodesController#new as HTML
  Parameters: {"podcast_id"=>"1"}
  Podcast Load (0.1ms)  SELECT  "podcasts".* FROM "podcasts" WHERE "podcasts"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
  Rendering episodes/new.html.erb within layouts/application
  Rendered episodes/new.html.erb within layouts/application (1.5ms)
  Podcast Load (0.2ms)  SELECT  "podcasts".* FROM "podcasts" WHERE "podcasts"."id" = ? ORDER BY "podcasts"."id" ASC LIMIT ?  [["id", 1], ["LIMIT", 1]]
Completed 200 OK in 25ms (Views: 21.3ms | ActiveRecord: 0.4ms)

这是我的剧集视图的new.html.erb:

<h1>New Episode</h1>

<% form_for ([@podcast, @episode]) do |f| %>
  <%= f.label :title %> <br>
  <%= f.text_field :title %>
  <br>
  <br>

  <%= f.label :description %>
  <%= f.text_area :description %>

  <%= f.submit %>

<% end %>

这是我的episodes_controller.rb文件:

class EpisodesController < ApplicationController
  before_action :find_podcast
  before_action :find_episode, only: [:show]

  def new
    @episode = @podcast.episodes.new
  end

  def create
    @episode = @podcast.episodes.new episode_params
    if @episode.save
      redirect_to podcast_episode_path(@podcast)
    else
      render 'new'
    end
  end

  private

  def episode_params
    params.require(:episode).permit(:title, :description)
  end
  def find_podcast
    @podcast = Podcast.find(params[:podcast_id])
  end

  def find_episode
    @episode = Episode.find(params[:id])
  end
end

如果您需要查看其他任何文件,请与我们联系。

1 个答案:

答案 0 :(得分:1)

您正在使用<%,当您需要使用<%=时,请点击此行:

<% form_for ([@podcast, @episode]) do |f| %>

你没有输出任何东西。 <%评估Ruby但不提供它,而<%=评估Ruby并且将输出发送到浏览器