Wie lösen die "nicht-Masse-weisen protected Attribute: translations_attributes" Fehler?

Ich bin mit Ruby, Ruby on Rails (3.2.2), globalize3 (0.2.0) und batch_translations (0.1.2) ruby-gems. Ich möchte lösen das folgende problem generiert, wenn mithilfe der batch_translations ruby-gem:

ActiveModel::MassAssignmentSecurity::Error in Admin::ArticlesController#update

Can't mass-assign protected attributes: translations_attributes

In meinem ROOT_RAILS/Gemfile - Datei habe ich:

...
gem 'globalize3'
gem 'batch_translations'

In meinem ROOT_RAILS/app/models/admin/article.rb - Datei habe ich:

class Admin::Article < ActiveRecord::Base
  translates :title

  # This is needed to make the batch_translations to work.
  accepts_nested_attributes_for :translations

  ...
end

In meinem ROOT_RAILS/app/views/admin/articles/_form.html.erb - Datei habe ich:

<%= form_for(@admin_article, :url => admin_article_path) do |f| %>
    <%= f.label :title %><br />
    English translation:
    <%= f.text_field :title %>

    Italiano translation:
    <%
      # Note: I am using the '<%= f...' instad of '<% f...' otherwise
      # batch_translations doesn't output the input field in the
      # front-end content.
    %>
    <%= f.globalize_fields_for :it do |g| %>
      <%= g.text_field :title %>
    <% end %>
<% end %>

In meinem ROOT_RAILS/app/controllers/admin/articles_controller.html.erb - Datei habe ich:

class Admin::ArticlesController < ApplicationController

  def update
    @admin_article = Article.find(params[:id])

    respond_to do |format|
      if @admin_article.update_attributes(params[:article])
        format.html { redirect_to admin_article_path(@admin_erticle), notice: 'Article was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @admin_article.errors, status: :unprocessable_entity }
      end
    end
  end

  ...
end

Wenn ich zeige, das edit-Formular funktioniert alles, aber wenn ich behaupte, die form bekomme ich die oben genannten Fehler. Wie kann ich das Problem lösen die oben genannten Fehler?


UPDATE

Fand ich die Lösung an, indem Sie den folgenden code in die ROOT_RAILS/app/models/admin/article.rb Datei:

class Admin::Article < ActiveRecord::Base
  translates :title

  attr_accessible :translations_attributes
  accepts_nested_attributes_for :translations

  ...
end

... aber die :translations_attributes zugänglich ist, ist es sicher?

InformationsquelleAutor user502052 | 2012-04-13
Schreibe einen Kommentar