我正在使用rails 4.0.2和globalize 4.0.0.alpha.3,但我無法用強參數列表將數據寫入翻譯數據庫。全球化的Gem和Rails 4強大的參數
我有一個報價模型和關注(OfferTranslationConcern)
class Offer < ActiveRecord::Base
include OfferTranslationConcern
end
的關注
module OfferTranslationConcern
extend ActiveSupport::Concern
included do
attr_accessor :attribute_translations
translates :name, :city, :includes, :notes, :description, :slug
end
end
控制器
def update
respond_to do |format|
if @offer.update(offer_params)
format.html { redirect_to @offer, notice: 'Offer was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @offer.errors, status: :unprocessable_entity }
end
end
end
而強大的參數定義
params.require(:user).permit('a lot of offer parameters', :attribute_translations => [:id, :name, :city, :includes, :notes, :description, :slug]
)
對於我正在使用的翻譯,例如西班牙語和意大利語(it和es)。當我更新了報價,我得到不允許的參數:它,ES
的參數如下:
"offer"=>{"attribute_translations"=>{"it"=>{"name"=>"dsfdsf", "city"=>"sdf", "includes"=>"sdfsdf", "notes"=>"sdfsd", "description"=>"fsdf"}, "es"=>{"name"=>"", "city"=>"", "includes"=>"", "notes"=>"", "description"=>""}}, "provider_id"=>"1",...a bunch of other stuff
現在我做到了這一定義的強大的參數工作
def offer_params
params.require(:offer).permit!
end
這項工作,但我不認爲這是最好的方法。所以,我的問題是如果有一種方法來定義參數列表並使其工作?
Thx爲答案。 –