mardi 5 mai 2015

NoMethodError in Blog::PostsController#create

Note: Rails newb here.

So, I recently created a Rails app with mongoid gem for use of MongoDB. I have a namespace route of :blog with a nest of resource of posts

Routes.rb:

Rails.application.routes.draw do
  namespace :blog do
    resources :posts
  end
end

The error comes from app/controllers/blog/post_controller.rb:

Class Blog::PostController < ApplicationController
  def create
   @post = Post.new(post_params)

  if @post.save
    redirect_to @post
  else
    render 'new'
  end
 end
end

I also have a 'post' model that comes with a title and body:

Class Post
 include Mongoid::Document
 field :title, type: String
 field :body, type: String
end

In new.html.erb:

<h1>Rails Sample Blog</h1>

<%= form_for :post, url: blog_post_path do |f| %>
  <div><%= f.label :title %><%= f.text_field :title %></div>
  <div><%= f.label :body %><%= f.text_area :body %></div>
<% end %>

Is there something I left out that I didn't catch? It's slowly haunting me.

Aucun commentaire:

Enregistrer un commentaire