2

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

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

错误在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
4

1 回答 1

1

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

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

gem 'inherited_resources', "1.3.1"

这为我解决了这个问题。

于 2013-04-12T14:17:35.280 回答