ActiveAdmin Rails 4 - 表单不保存记录?

时间:2014-03-07 16:17:28

标签: ruby-on-rails ruby ruby-on-rails-4 activeadmin

我想知道为什么ActiveAdmin不会通过rails 4中的表单保存记录? 当我编辑记录的标题和内容时,我收到消息“已成功更新”,但记录未保存。提前致谢

static_pages.rb

ActiveAdmin.register StaticPage do
  menu false
  config.filters = false

  form do |f|
    f.inputs "Details" do
      f.input :unique_identifier
      f.input :title
      f.input :content, :label => "Content"
    end
    f.actions
  end

end

static_page.rb

class StaticPage < ActiveRecord::Base
  validates_uniqueness_of :unique_identifier
end

迁移

class CreateStaticPages < ActiveRecord::Migration
  def change
    create_table :static_pages do |t|
      t.string :unique_identifier
      t.string :title
      t.text :content
      t.boolean :is_enabled

      t.timestamps
    end
  end
end

的Gemfile

source 'https://rubygems.org'

ruby '2.0.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.0.rc1'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

# Fameus
gem "twitter", git: 'https://github.com/sferik/twitter.git'


# GUI
gem 'bcrypt-ruby', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt'
gem 'inherited_resources', github: 'josevalim/inherited_resources'
gem 'best_in_place'



# API
gem 'rabl'
gem 'oj'

# Delayed Job
gem 'delayed_job_active_record'

# mysql
gem 'mysql2'
gem 'magic_encoding'

#
gem 'unicorn'

#
gem 'mixpanel_client'

# PArser
gem 'httparty'

# Monitor Performance
gem 'newrelic_rpm'

# Devise Localization
gem 'devise-i18n'

# Rails
gem 'protected_attributes'

# Assets
gem 'rails_12factor', group: :production

# Cache
gem 'memcachier'
gem 'dalli'

# Gem pg
gem 'pg'

gem 'spring', group: :development

group :production do
  gem 'thin'
end

gem 'formtastic', github: 'justinfrench/formtastic'
gem 'ransack', github: 'activerecord-hackery/ransack', branch: 'rails-4.1'
gem 'polyamorous', github: 'activerecord-hackery/polyamorous'
gem 'activeadmin', github: 'gregbell/active_admin', branch: 'master'

2 个答案:

答案 0 :(得分:1)

我认为不应该将attr_accessible放在您的模型中,而应该尝试将其置于您menu false

正上方的有效管理员static_pages.rb的顶部。
permit_params :unique_identifier, :title, :content

答案 1 :(得分:0)

<强>解

通过在模型中添加以下行来解决该问题:

attr_accessible :unique_identifier, :content, :title, :is_enabled

根据Rails 4文档,attr_accessible只在Rails 3中是必需的。因此它看起来更像是activeadmin上的一个bug。