When I submit my form I'm seeing this error.
NoMethodError in SellersController#create
undefined method `sellers' for #
match = match_attribute_method?(method.to_s)
match ? attribute_missing(match, *args, &block) : super
It's coming from this line in the sellers_controller.rb
def create
@seller = current_user.sellers.build(seller_params)
end
Relevant part of the model:
class Seller < ActiveRecord::Base
belongs_to :user
end
View: new.html.erb
<%= form_for(@seller) do |f| %>
...
<% end %>
Rake routes runs without an error.
I'm missing something with how rails assumes the db/view/model
is for my controller. I've been looking through the documentation but nothing is coming to mind.
routes.rb
Rails.application.routes.draw do
resources :sellers
end
create_sellers.rb
class CreateSellers < ActiveRecord::Migration
def change
create_table :sellers do |t|
....
t.references :user, index:true, foreign_key: true
I've already tried
- restarting rails
- closing and reopening the terminal
- rolling back the migration and trying it again (no error on migration)
I've looked at the migration/model/controller view and I am not seeing the problem (so Its probably there and obvious).
user.rb
class User < ActiveRecord::Base
has_one :seller
end