0

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

Bojan Kseneman
  • 15,488
  • 2
  • 54
  • 59
user3841707
  • 69
  • 1
  • 3

2 Answers2

1

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
djaszczurowski
  • 4,385
  • 1
  • 18
  • 28
  • I getting a new error Unable to autoload constant SongsController, expected /home/ubuntu/workspace/Hackstore/app/controllers/songs_controller.rb to define it – user3841707 May 23 '15 at 13:26
  • now error changed to Circular dependency detected while autoloading constant SongsController – user3841707 May 23 '15 at 13:34
  • my mistake, I wrote `app/controller/songs_controller.rb`, and forgot to add s to controller. The correct path: `app/controllers/songs_controller.rb` – djaszczurowski May 23 '15 at 13:35
0

Rename your controller as SongsController

Vrushali Pawar
  • 3,753
  • 1
  • 13
  • 22