我正在将独白博客引擎用于现有的 rails 4 应用程序。我通过他们的 github 页面按照他们的说明进行操作,并且在 rails 控制台中创建第一个用户时遇到了批量分配错误。我通常会进入模型并允许批量分配,但是我似乎无法在我的 rails 应用程序中找到任何用于独白的模型文件。当我在我的网站上导航到 /blog 时,我看到了模板,当我转到 /blog/login 时,我看到了登录页面。我还应该注意,我已将独白视图、模型、控制器、助手等的内容复制到我的独白文件中。users_controller.rb 文件包含一个应允许批量分配的受保护方法。
错误是:
WARNING: Can't mass-assign protected attributes for Monologue::User: name, email, password, password_confirmation
我在我的 gemfile 中加入了独白:
source 'https://rubygems.org'
ruby '1.9.3'
gem 'rails', '4.1.0'
gem 'devise', '3.0'
gem 'google-analytics-rails'
gem 'meta-tags'
gem 'databasedotcom'
gem 'databasedotcom-rails'
gem 'protected_attributes'
gem 'thin'
group :development do
gem 'pg'
end
group :production do
gem 'newrelic_rpm'
gem 'rails_12factor'
end
gem 'sass-rails', '~> 4.0.2'
gem 'bootstrap-sass'
gem 'sprockets', '2.11.0'
gem 'sprockets-rails'
gem 'coffee-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'jquery-rails', "~> 2.1.0"
gem 'font-awesome-rails'
gem 'monologue', github: 'jipiboily/monologue'
user_controller.rb 在 app/controllers/monologue/admin/users_controller.rb
class Monologue::Admin::UsersController < Monologue::Admin::BaseController
before_filter :load_user, except: [:index, :new, :create]
def edit
end
def new
@user = Monologue::User.new
end
def update
if @user.update user_params
flash.notice = "User modified"
redirect_to admin_users_path
else
render :edit
end
end
def destroy
if @user.destroy
redirect_to admin_users_path, notice: I18n.t("monologue.admin.users.delete.removed", user: @user.name)
else
redirect_to admin_users_path, alert: I18n.t("monologue.admin.users.delete.failed", user: @user.name)
end
end
def create
@user = Monologue::User.new user_params
if @user.save
flash.notice = I18n.t("monologue.admin.users.create.success")
redirect_to admin_users_path
else
render :new
end
end
def index
@users = Monologue::User.all
end
private
def load_user
@user = Monologue::User.find(params[:id])
end
def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation)
end
end
我的 Routes.rb 文件:
# Blog URL
mount Monologue::Engine, at: '/blog' # or whatever path, be it "/blog" or "/monologue"