Reputation: 69
I'm getting an error like that, I'm new in rails.
my routes.rb
Rails.application.routes.draw do
get 'welcome' => 'page#search'
resources :songs
end
search.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
path
welcome_path GET /welcome(.:format) page#search song_new_path POST /song/new(.:format) song#new songs_path GET /songs(.:format) songs#index POST /songs(.:format) songs#create new_song_path GET /songs/new(.:format) songs#new edit_song_path GET /songs/:id/edit(.:format) songs#edit song_path GET /songs/:id(.:format) songs#show PATCH /songs/:id(.:format) songs#update PUT /songs/:id(.:format) songs#update DELETE /songs/:id(.:format) songs#destroy
Upvotes: 0
Views: 1732
Reputation: 4533
you declared resources :songs
in your routes file, so Rails expecte SongsController inheriting from ApplicationController in your app/controllers folder. If you do not have this controller, create new file:
app/controller/songs_controller.rb
class SongsController < ApplicationController
# add implementation of CRUD methods
def index
end
def show
end
def new
end
# ...
end
Upvotes: 1