0

我遇到了这样的错误,我是 Rails 的新手。

我的路线.rb

Rails.application.routes.draw do
get 'welcome' => 'page#search'

resources :songs
end

搜索.html.erb

<%=form_for @song do |f|%>
<%=f.text_field :search%>
<%=f.submit 'Search'%>
<%end%>

page_controller.rb

class PageController < ApplicationController
attr_accessor :a

def search
  @songs = Song.all
  @song = Song.new
end

def new
  @song = Song.new
end

def Create
  @song = Song.new()
 if @song.save 
  rediect_to ''
 else
  render new
 end
end

 def parameter
  params.require(@song)
 end
end

小路

welcome_path GET /welcome(.:format) 页面#search song_new_path POST /song/new(.:format) song#new song_path GET /songs(.:format) song#index POST /songs(.:format) song#create new_song_path GET /songs/new(.:format) 歌曲#new edit_song_path GET /songs/:id/edit(.:format) 歌曲#edit song_path GET /songs/:id(.:format) 歌曲#show PATCH /songs/: id(.:format) 歌曲#update PUT /songs/:id(.:format) 歌曲#update DELETE /songs/:id(.:format) 歌曲#destroy

4

2 回答 2

1

resources :songs在你的路由文件中声明,所以 Rails 期望 SongsController 从你的 app/controllers 文件夹中的 ApplicationController 继承。如果您没有此控制器,请创建新文件:

app/controller/songs_controller.rb

class SongsController < ApplicationController

  # add implementation of CRUD methods
  def index

  end

  def show

  end

  def new

  end

  # ...
end
于 2015-05-23T11:29:31.493 回答
0

将控制器重命名为SongsController

于 2015-05-23T11:29:20.160 回答