0

我所看到的

以下是我的 Track 模板:

app/views/tracks/index.html.erb

<h1>Playlist</h1>

<%= form_for @track do |f| %>
    <%= f.error_messages %>
    <p>
        <%= f.text_field :youtube_url %>
        <%= f.submit 'Add' %>
    </p>
<% end %>

<hr />

<% if Track.first == nil %>
<p>Database is empty!</p>
<%else%>
<% @tracks.each do |track| %>
  <ul>
    <li><%= track.youtube_url %></li>
  </ul>
<% end %>
<% end %>

显然,由于某种原因没有显示输入字段。

其他相关文件:app/controllers/tracks_controllers.rb

class TracksController < ApplicationController
def index
    @track = Track.new
    @tracks = Track.all
end

def create 
    @track = Track.new(params[:track])
    render :action=>"index"

end

def delete
    @track = Track.find(params[:id])
    @track.destroy

    redirect_to(tracks_url)
end
end

路线.rb

Music::Application.routes.draw do
   resources :tracks
end

track.rb 类 Track < ActiveRecord::Base attr_accessible :title, :youtube_url end

我究竟做错了什么?

4

1 回答 1

2

你必须把<%=开始标签放在你的form_for而不是<%.

<%= form_for @track do |f| %>
    <%= f.error_messages %>
    <p>
        <%= f.text_field :youtube_url %>
        <%= f.submit 'Add' %>
    </p>
<% end %>
于 2013-06-16T22:01:38.347 回答