【问题标题】:Rails 4 - mailboxer attr_accessibleRails 4 - 邮箱 attr_accessible
【发布时间】:2013-08-13 18:38:20
【问题描述】:

我正在尝试让 Rails4 上的 Mailboxer 正常工作,但没有任何运气。

我的 conversations_controller.rb 看起来像这样 ->

class ConversationsController < ApplicationController
before_filter :authenticate_user!
helper_method :mailbox, :conversation

def create
    recipient_emails = conversation_params(:recipients).split(',')
    recipients = User.where(email: recipient_emails).all

    conversation = current_user.
        send_message(recipients, *conversation_params(:body, :subject)).conversation

    redirect_to conversation
end

def reply
    current_user.reply_to_conversation(conversation, *message_params(:body, :subject))
    redirect_to conversation
end

def trash
    conversation.move_to_trash(current_user)
    redirect_to :conversations
end

def untrash
    conversation.untrash(current_user)
    redirect_to :conversations
end

private

def mailbox
    @mailbox ||= current_user.mailbox
end

def conversation
    @conversation ||= mailbox.conversations.find(params[:id])
end

def conversation_params(*keys)
    fetch_params(:conversation, *keys)
end

def message_params(*keys)
    fetch_params(:message, *keys)
end

def fetch_params(key, *subkeys)
    params[key].instance_eval do
        case subkeys.size
            when 0 then self
            when 1 then self[subkeys.first]
            else subkeys.map{|k| self[k] }
        end
    end
end

结束

和我的 application_controller.rb 像这样 ->

class ApplicationController < ActionController::Base
before_filter :configure_permitted_parameters, if: :devise_controller?
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception



protected

def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) do |u|
        u.permit(:name, :email, :password, :password_confirmation, :provide, :uid)
    end
    devise_parameter_sanitizer.for(:account_update) do |u|
        u.permit(:name, :email, :password, :current_password, :password_confirmation, :first_name, :last_name, :user_bio,
                         :country, :gender, :facebook_link, :twitter_link, :pinterest_link, :provider, :uid, :recipients, :body,
                         :subject, :conversations, :conversation, :message, :mailbox)
    end
end

def conversations_params
    params.require(:conversations).permit(:recipients, :body, :subject,
                                                                                :conversations, :conversation, :message)
end

结束

加载页面时我得到 ->

`attr_accessible` is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add `protected_attributes` to your Gemfile to use old one.

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 strong-parameters attr-accessible mailboxer


    【解决方案1】:

    基于https://github.com/ging/mailboxer/pull/159,您可以:

    • protected_attributes 添加到您的gemfile 中
    • 使用ging/mailboxer的master分支

    【讨论】:

    • 嗯,只有我正在使用的主分支:(
    • 我很确定您使用的是最后一个部署的稳定 gem。如果您使用的是 edge/master,则为 gem 'mailboxer', github: 'ging/mailboxer'
    • 我不太明白这个(对不起,我有点新)。在 Github 上只有一个分支,所以如果我放入我的 gemfile gem 'mailboxer' 或 gem 'mailboxer', github: 'ging/mailboxer' 有什么区别?谢谢
    • gem 'mailboxer' 将使用最后一个稳定部署的 gem 版本,它不包括 master 分支中的许多更改。如果您指定gem 'mailboxer', github: 'ging/mailboxer',您将获得所有最新更改(边缘)。
    • 这是运行 1.0-stable 和最前沿的区别。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-08
    • 2013-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多