strong-parameters

Rails 4 Strong Parameters - Handling Missing Model Params Hash

亡梦爱人 提交于 2019-12-30 05:44:07
问题 Models: Posts and Users Post belongs_to :user User has_many :posts Simple. Assuming a few users exist, we visit the edit page for a Post. <%= form_for @post do |f| %> ... <% User.all.each do |user| %> <div><%= f.radio_button "user_id", user.id %></div> <% end %> ... The Post's Controller leverages Rails 4 strong parameters. params.require(:post).permit(:user_id) Assume the edit post form only has the radio buttons as fields. Problem: ActionController::ParameterMissing exception is thrown.

Deep Nested Rails 4 Form

烈酒焚心 提交于 2019-12-30 03:14:18
问题 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

Devise and Strong Parameters

℡╲_俬逩灬. 提交于 2019-12-28 05:35:38
问题 I would like to know how to integrate both of this gems(devise + Strong Parameters), since strong params will likely be added to the rails core in 4.0 any help is welcome thanks 回答1: Update for devise 4.x class ApplicationController < ActionController::Base before_filter :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:username]) devise_parameter_sanitizer.permit(:sign_in, keys: [:username

undefined method `permit' for #<String:0x007f66ec6ff180> ruby on rails

谁说胖子不能爱 提交于 2019-12-25 18:25:46
问题 I read many links specially on stackoverflow but could not find the solution as there was some difference . so I want to make my point clear as explained below: I have an ajax call pointing to my controller and it has only one parameter google_searched_locations , which is basically contains json string google_searched_locations [{"geometry":{"location":{"J":31.482273,"M":74.33069999999998}},"icon":"https://maps.gstatic.com/mapfiles /place_api/icons/restaurant-71.png","id":

Configuring strong parameters for dynamic keys

前提是你 提交于 2019-12-25 07:49:47
问题 I'm attempting to provide a form that allows an admin to edit all values of a particular model Submission , almost as though it was a spreadsheet. Submission is comprised of one string field :domain . The problem is that I can't figure out how to deal with strong params within this context. I've found similar examples of dealing with dynamic keys like this one but I can't quite figure out how to apply them to my parameter structure. I think I'm just not clear enough on how tap works. Here's

Unpermitted parameter in Rails 4 when submitted nested attributes, has_many associated form

人盡茶涼 提交于 2019-12-25 07:39:33
问题 I have two models ( lead which has_many :quote_metals and accepts_nested_attributes_for :quote_metals and quote_metal which belongs_to :lead ). I am trying to write the information submitted in the form to the different datatables. There should just be one lead and multiple (no exact number) of quote_metals. I am receiving an error saying that Unpermitted parameter: quote_metal . Here are the parameters: Processing by LeadsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity

Rails 4 permit any keys in the hash

时光怂恿深爱的人放手 提交于 2019-12-25 04:46:25
问题 I pass a params like this { "utf8" => true, "supply" => { "items" => { 111 => 112, 89 => 10}, "another_params" => "something" } } My supply_params are: params.fetch(:supply, {}).permit(:another_params, items: {}) But I get an unpermitted parameters 111 and 89 . How can I make items permit all kinds of keys? 回答1: This thread in github provides a solution: def supply_params params.require(:supply).permit(:another_params).tap do |whitelisted| whitelisted[:items] = params[:supply][:items] if

Nesting Carrierwave images in Rails 4

狂风中的少年 提交于 2019-12-25 04:09:06
问题 This is actually a two part question For the record - I am using Simple_form, Carrierwave and awesome_nested_fields gems. In my app I have events, each event has a speaker, and each speaker has a picture. Pictures are not a separate table, they're stored under 'speakers' event.rb class Event < ActiveRecord::Base belongs_to :type ... has_many :speakers accepts_nested_attributes_for :speakers, allow_destroy: true ... speaker.rb class Speaker < ActiveRecord::Base belongs_to :event mount_uploader

Confused about strong parameters with Devise

。_饼干妹妹 提交于 2019-12-24 23:19:02
问题 I have the following Devise registration form (with irrelevant markup omitted): <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { id: "payment-form" }) do |f| %> <%= f.fields_for resource.paid_account do |pa| %> <%= pa.collection_select :account_plan_id, @account_plans, :id, :name_with_price %> <% end %> <% end %> This form spits out the following HTML: <select id="user_paid_account_account_plan_id" name="user[paid_account][account_plan_id]"> <option

Why am I getting strong parameter errors in the Rails Console in rails 5?

我怕爱的太早我们不能终老 提交于 2019-12-24 21:26:17
问题 I want to call this in my console ( ap is the awesome print gem): ap Purchase.last(10) but I get this error: ActionController::UnfilteredParameters: unable to convert unpermitted parameters to hash It works like this: irb(main):020:0> ap Purchase.last #<Purchase:0x00007f86b792a320> { :id => 28445, :user_id => 10177, :product_id => nil, :product_type => nil, :price => 9.0, :gateway_code => nil, :gateway_msg => nil, :gateway_response => nil, :created_at => Fri, 18 May 2018 22:20:10 UTC +00:00,