1

不知道为什么我似乎收到此错误,因为我有适当数量的末端。该应用程序正在运行 - 然后我安装了设计,它就下地狱了。我卸载了设计以返回工作版本,但现在我似乎收到了如下所示的错误。

错误信息

SyntaxError in SongsController#index
/Users/user/Sites/leap2/leap2/app/controllers/songs_controller.rb:13: syntax error, unexpected end-of-input, expecting keyword_end

Songs_controller.rb

  class SongsController < ApplicationController
  before_action :set_song, only: [:show, :edit, :update, :destroy]

  def index
    @songs = Song.all
  end

  def new
    @song = Song.new
  end

  def show
  end

  def edit
  end

  def create
    @song = Song.new(song_params)

    respond_to do |format|
      if @song.save
        format.html { redirect_to @song, notice: 'Song was added successully'}
        format.json {render action: 'show', status: :created, location: @song}

      else
        format.html { render action: 'new' }
        format.json { render json: @song.errors, status: :unprocessable_entity }

      end
    end
  end

  def update
   respond_to do |format|
     if @song.update(song_params)
       format.html {redirect_to @song, notice: 'Song was successfully updated.' }
       format.json {head :no_content }
     else
       format.html {render action: 'edit' }
       format.json {render json: @song.errors, status: :unprocessible_entity }
     end
   end
 end

   def destroy
     @song.destroy
     respond_to do |format|
       format.html { redirect_to songs_url }
       format.json { head :no_content }
     end
   end


     private

     def set_song
       @song = Song.find(params[:id])
     end

     def song_params
       params.require(:song).permit(:title, :artist, :bio, :track)
     end
  end

显示.html.erb

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


    <p>
    <strong>Title:</strong>
    <%= @song.title %>
    </p>

    <p>
    <strong>Bio:</strong>
    <%= @song.bio %>
    </p>

    <p>
    <strong>Audio:</strong>
    <%= audio_tag (@song.track.url), controls: "controls" %>
    </p>


    <br /><br />


    <%= link_to 'Edit', edit_song_path(@song), class: "button small secondary"%> 
    <%= link_to 'Back', songs_path,  class: "button small secondary" %>

_form.html_erb

<%= form_for @song, :html => { :multipart => true } do |f| %>
<% if @song.errors.any? %>
<div id="error_explanation">
    <h2><%= pluralize(@song.errors.count, "error") %> prohibited this song from being saved:</h2>

     <ul>
      <% @song.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

    <div class="row">
        <div class="large-6 columns">
    <div class="field">
    <%= f.label :title %>
    <%= f.text_field :title %>
    </div>

    <div class="field">
    <%= f.label :bio %>
    <%= f.text_area :bio %>
    </div>

    <p>
    <%= f.file_field :track%>
    </p>

    <div class="actions">
        <%= f.submit value: "Upload" %>
    </div>

    <% end %>
        </div>

        <div class="large-6 columns"><h3>Submit your own song or a personal favourite and watch it climb the charts! </h3>
        </div>
    </div>
4

1 回答 1

0

application_controller.rb你有一个额外的结束。

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  def authorize
    redirect_to new_user_session_path, notice: "You have to be logged in to submit." 
     if current_user.nil?
  end
end
end
于 2013-07-13T07:35:37.307 回答