strong-parameters

Serialize array with strong_parameters

馋奶兔 提交于 2019-11-30 16:51:38
问题 I am trying to save a array using the strong_parameters gem. But I am having issues with how the form is sending my array. The params look like this: > params[:circuit] => {"title"=>"Some title", ..., "viewable_tasks"=>{"0"=>"woop", "1"=>"dee", ...}} And my circuit_params function looks like: def circuit_params params.require(:circuit).permit(:title, :id, viewable_tasks: { }, ... ) end I can't seem to get the syntax to allow my params to work. What I get in my console is: > circuit_params =>

Rails 4/Devise/MongoDB: “Unpermitted parameters” using custom properties and strong parameters

独自空忆成欢 提交于 2019-11-30 14:04:25
Trying to add a nested custom attribute, Profile (a Mongoid document), to my devise User class. When the Devise registration form is submitted, it should create both a User and a corresponding Profile object as well. I'd like the end-result to look something like this in my MongoDB: User: { # Devise fields: "email": "my@email.com", ... # Custom field "profile" : "<object_id>" } Profile: { "first_name": "Dave", .... } Unfortunately, I am receiving this in my console whenever I submit my registration. It successfully creates a User but fails to create an associated Profile. Started POST "/" for

Unpermitted parameters in rails 4

喜夏-厌秋 提交于 2019-11-30 11:33:40
I read about collection_check_boxes but I don't understand how can I set the checked values. I have the following model: class Objective < ActiveRecord::Base has_many :indicators has_many :objective_children, class_name: "Objective", foreign_key: "parent_id" def objective_ids objective_children.collect{|o| o.id} end def objective_ids= objectives_ids objectives_ids.each do |id| objective_children << Objective.find(id) end end end edit view: <%= form_for(@objective) do |f| %> <%= f.collection_check_boxes :objective_ids, Objective.all, :id, :name %> <%= f.submit %> <% end %> the html checkbox are

Deep Nested Rails 4 Form

我们两清 提交于 2019-11-30 09:05:52
I have 3 models Item which accepts nested attributes for questions and questions accept nested attributes for answers. I'm trying to create an item which has a question and an answer in the same form. item.rb class Item < ActiveRecord::Base has_many :questions, dependent: :destroy accepts_nested_attributes_for :questions end question.rb class Question < ActiveRecord::Base belongs_to :item has_many :answers, dependent: :destroy accepts_nested_attributes_for :answers end answer.rb class Answer < ActiveRecord::Base belongs_to :question end item_controller.rb class ItemsController <

Rails 4/Devise/MongoDB: “Unpermitted parameters” using custom properties and strong parameters

旧巷老猫 提交于 2019-11-29 19:23:56
问题 Trying to add a nested custom attribute, Profile (a Mongoid document), to my devise User class. When the Devise registration form is submitted, it should create both a User and a corresponding Profile object as well. I'd like the end-result to look something like this in my MongoDB: User: { # Devise fields: "email": "my@email.com", ... # Custom field "profile" : "<object_id>" } Profile: { "first_name": "Dave", .... } Unfortunately, I am receiving this in my console whenever I submit my

strong parameters not accepting array

空扰寡人 提交于 2019-11-29 17:45:43
问题 I have this in my view which is a multiselect checkbox Model class User < ActiveRecord::Base has_many :user_roles, :dependent => :destroy accepts_nested_attributes_for :user_roles, :allow_destroy => true has_many :roles, :through => :user_roles end view <%= check_box_tag 'user[role_ids][]', role.id, user.blank? ? nil : user.roles.include?(role) ,id: dom_id(role)%> the strong parameters for this is written as def user params.require(:user).permit(:first_name,{:role_ids => []}) end But on

Unpermitted parameters in rails 4

谁都会走 提交于 2019-11-29 17:17:35
问题 I read about collection_check_boxes but I don't understand how can I set the checked values. I have the following model: class Objective < ActiveRecord::Base has_many :indicators has_many :objective_children, class_name: "Objective", foreign_key: "parent_id" def objective_ids objective_children.collect{|o| o.id} end def objective_ids= objectives_ids objectives_ids.each do |id| objective_children << Objective.find(id) end end end edit view: <%= form_for(@objective) do |f| %> <%= f.collection

Strong parameters for nested attributes returns “unpermitted parameters” when empty array

懵懂的女人 提交于 2019-11-29 09:57:08
Assuming a User model using Rails4 with strong_parameters. class User < ActiveRecord::Base has_secure_password accepts_nested_attributes_for :identity // rest of code omitted for brevity end If I refer to the guide I should be able to do def user_params params.require(:user).permit(:email, identity_attributes: []) end to allow mass_assignment of each identity_attributes whatever their names or number. But this run in a "Unpermitted parameters: identity_attributes" But if I specify the identity_attributes it works def user_params params.require(:user).permit(:email, identity_attributes: [:last

Paperclip in Rails 4 - Strong Parameters Forbidden Attributes Error

旧街凉风 提交于 2019-11-29 04:04:19
Having a problem with a Paperclip upload in Rails 4 - failing on ForbiddenAttributesError (strong parameters validation). Have the latest paperclip gem and latest rails 4 gems. I have a model "Image" with an attached file "upload" in the model: has_attached_file :upload, :styles => { :review => ["1000x1200>", :png], :thumb => ["100x100>", :png]}, :default_url => "/images/:style/missing.png" The image model was created with a scaffold, and I added paperclip migrations. The form partial was updated to use f.file_field :upload the form generates what appears to be a typical set of paperclip

rails 4 strong params + dynamic hstore keys

左心房为你撑大大i 提交于 2019-11-28 21:31:18
I'm having a problem overcoming the new strong params requirement in Rails 4 using Hstore and dynamic accessors I have an Hstore column called :content which I want to use to store content in multiple languages, ie :en, :fr , etc. And I don't know which language upfront to set them in either the model or the controller. store_accessor :content, [:en, :fr] #+226 random other il8n languages won't work. How can I override strong params (or allow for dynamic hstore keys) in rails 4 for one column? params.require(:article).permit( :name, :content, :en, :fr #+226 random translations ) Short of...