WaterTrash
WaterTrash

Reputation: 438

Embedded ruby not showing up on webpage

I'm trying to create new episode form for a podcast website and when I try to reload the page nothing happens and I get the error:

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)

This is my new.html.erb for my episode view:

<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 %>

This is my episodes_controller.rb file:

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

Let me know if you need to see any other files.

Upvotes: 0

Views: 91

Answers (1)

user229044
user229044

Reputation: 239250

You're using <%, and when you need to use <%=, on this line:

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

You're not outputting anything. <% evalutes Ruby but doesn't render it, while <%= evaluates Ruby and sends the output to the browser.

Upvotes: 1

Related Questions