ruby on rails - undefined method `to_model' for 1:Fixnum -
artist/show.html.erb
<% if @artist.songs.any? %> <div class="col-md-8"> <% @artist.songs.each |song| -%> <span><%= link_to song.title, song.artist %></span> <% end -%> </div> <% end %>
routes.rb
resources :artists, :path => "/music", only: [:show] resources :songs, :path => "/", only: [:show] end
artist controller
class artistscontroller < applicationcontroller def show @artist = artist.friendly.find(params[:id]) end end
song controller
class songscontroller < applicationcontroller def show artist = artist.friendly.find(params[:artist_id]) @song = artist.songs.find(params[:id]) end end
artist model
class artist < activerecord::base extend friendlyid friendly_id :name, use: :slugged has_many :songs, dependent: :destroy validates :name, presence: true, length: { maximum: 50 }, uniqueness: { case_sensitive: false } def slug=(value) if value.present? write_attribute(:slug, value) end end end
song model
class song < activerecord::base belongs_to :artist default_scope -> { order(:title) } validates :artist_id, presence: true validates :title, presence: true, length: { maximum: 140 } rails_admin configure :artist label 'artist name: ' end end
gemfile
source 'https://rubygems.org' gem 'rails', '4.2.1' gem 'friendly_id', '~> 5.1.0' gem 'sorcery' gem 'validates_email_format_of' gem 'bootstrap-sass', '3.2.0.0' gem 'sqlite3', '1.3.10' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.1.0' gem 'jquery-rails' gem 'turbolinks' gem 'jbuilder', '~> 2.0' gem 'sdoc', '0.4.0', group: :doc gem 'delayed_job_active_record' gem 'rails_admin' gem 'font-awesome-sass-rails' gem 'coffee-script-source', '1.8.0' group :development, :test gem 'byebug' gem 'web-console', '~> 2.0' gem 'minitest' end gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
when enter http://localhost:3000/music/ed-sheeran
it give me error message
undefined method `to_model' 1:fixnum
i'm missing obvious.
Comments
Post a Comment