Reputation: 857
I'm building a simple setup of ActiveAdmin to get my feet wet with basic admin coding in RoR. Nothing fancy. I generated a "post" controller and resource and model, as shown below. My issue is that I am still getting the following error:
NoMethodError in Admin::PostsController#index
undefined method `rails' for #<Admin::PostsController:0x00000107ad3038>
It's correct in that I haven't defined a rails
method, but I also haven't called one. In fact, there's no rails
method called anywhere in any of my code. This leads me to believe that I have a syntax issue somewhere, but I can't seem to find it. Please help me make sense of this.
/admin/post.rb
ActiveAdmin.register Post do
scope_to :rails
permit_params :title, :slug, :blurb, :content, :category_id
index do
column :title
column :slug
column :blurb
column :created_at
actions
end
form :html => {:enctype => "multipart/form-data"} do |f|
f.inputs "Details" do
f.input :title
f.input :slug
f.input :blurb
f.input :category
f.input :content, :as => :text
end
f.inputs "Images" do
f.input :image, :label => 'Post Image', :as => :file
end
f.actions
end
end
/controllers/posts_controller.rb
class PostsController < ApplicationController
def index
@posts = Post.all
end
def show
@post = Post.find(params[:id])
end
end
/models/post.rb
class Post < ActiveRecord::Base
belongs_to :category
scope :rails, -> { where(category_id: 1) }
end
As you can see, I never call any rails
method in my code. Where is that error coming from?
Upvotes: 0
Views: 607
Reputation: 5322
This error is probably coming from this line in your view admin/post.rb:
scope_to :rails
Try commenting that out.
Then try something like this instead:
ActiveAdmin.register Post do
controller do
def resource
Post.where(category_id: 1)
end
end
end
Upvotes: 1