Koes Bong
Koes Bong

Reputation: 1113

Undefined method Rails error

I am a Rails noob and not sure what is causing the Undefined method error. Here's my code:

routes.rb

namespace :dashboard do
  resources :subjects
end

new.html.rb

<%= form_for(@subject) do |f| %>
  <%= f.label :name %>
  <%= f.text_field :name %>
  <%= f.submit "Submit" %>
<% end %>

subjects_controller.rb

module Dashboard
  class SubjectsController < ApplicationController

    def new
      @subject = Subject.new
    end
  end
end

When I load /dashboard/subjects/new in the browser, I get the following error on the form_for(@subject) line

undefined method `subjects_path' for #<#<Class:0x007f951e0f2b38>:0x007f951e0f18f0>

What am I doing wrong here?

Upvotes: 0

Views: 64

Answers (1)

maximus ツ
maximus ツ

Reputation: 8065

This should work since you are having namespaced resource

<%= form_for([:dashboard, @subject]) do |f| %>

Upvotes: 4

Related Questions