ActiveAdmin - 无法创建模型“评级”

时间:2013-04-07 13:32:24

标签: ruby-on-rails model activeadmin

当我点击“新评级”时,我不知道为什么会出现错误。似乎其他模型的创建也会产生同样的错误。

这是错误消息:“结构中没有成员'评级'”

错误发生在 inherited_resources-1.4.0 / lib / inherited_resources / base_helpers.rb

的第316行

完整的堆栈跟踪:https://gist.github.com/depy/5330548

313       # extract attributes from params
314       def build_resource_params
315         parameters = respond_to?(:permitted_params) ? permitted_params : params
316         rparams = [parameters[resource_request_name] || parameters[resource_instance_name] || {}]
317         if without_protection_given?
318           rparams << without_protection
319         else
320           rparams << as_role if role_given?
321         end

这是我的评分模型:

class Rating < ActiveRecord::Base

  validates_uniqueness_of :task_id, :scope => [:user_id, :user_role], :message => 'You      have already rated this task'
  validates_inclusion_of :user_role, :in => %w( client contractor )
  validates_presence_of :task_id, :user_id
  validates_presence_of :score, :message => 'Please rate your satisfaction'

  belongs_to :task
  belongs_to :user
end

这是我的ActiveAdmin Rating.rb

ActiveAdmin.register Rating do
  controller do; include StrongAdmin; end

  # list
  index do
    column :user_id
    column :task_id
    column :comment
    column :score
    default_actions
  end

  # single
  show do |rating|
    attributes_table do
      row :id
      row :rater do
        task_id = Rating.find(params[:id]).task_id
        div do
          Task.find(task_id).client.full_name + " [" +  Task.find(task_id).client.id.to_s+"]"
        end
      end
      row :user
      row :user_role
      row :task
      row :score
      row :comment
      row :created_at
    end
    active_admin_comments
  end

end

这是我的Gemfile:

source 'https://rubygems.org'
ruby "1.9.3"

gem 'rails'
gem 'pg' # Database (PostgreSQL)

group :assets do
  gem 'sass-rails'
  gem 'uglifier'
  gem 'bourbon'
  gem 'jquery-fileupload-rails'
  gem 'jquery-rails'
  gem 'asset_sync'
end

group :production do
  gem 'honeybadger'
  gem 'newrelic_rpm' # App monitoring
end

gem 'bcrypt-ruby' # Secure passwords
gem 'devise' # Authentication
gem 'unicorn' # Webserver
gem 'redis'# Session storage and Task applications
gem 'carrierwave' # File uploading
gem 'mini_magick' # Image processing
gem 'kaminari'# Pagination
gem 'turbolinks' # Pushstate and async loading
gem 'strong_parameters' # Attribute accessible replacement
gem 'dalli' # Memcached interface
gem 'fog' # CDN connector
gem 'activeadmin' # (user) administration
gem 'cancan' # Authorization
gem 'gibbon' # Mailchimp API wrapper
gem 'multi_json'
gem 'nokogiri' # HTML parser for error messages
gem 'pusher' # Hosted websockets
gem 'sidekiq' # Async processing
gem 'draper' # Decorator
gem 'lograge' # Improved logger
gem 'slim'
gem 'sinatra', :require => nil

group :development do
  gem 'sqlite3'
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'meta_request'
  gem 'quiet_assets'
end

group :test, :darwin do
  gem 'rb-fsevent'
end

group :test do
  gem 'rspec-rails'
  gem 'factory_girl_rails'
  gem 'capybara'
  # gem 'capybara-webkit'
  gem 'database_cleaner'
  gem 'launchy'
  gem 'faker'
end

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。我从0.5.1更新了ActiveAdmin。到0.6.0。继承的资源gem也更新为1.4.0。

由于ActiveAdmin需要1.3.1或更高版本,因此您可以锁定gem中的版本

gem 'inherited_resources', "1.3.1"

这解决了我的问题。