strong-parameters

Nested checkboxes in Rails

与世无争的帅哥 提交于 2021-02-08 08:59:43
问题 I'm trying to create an event app where each event has multiple tables and each table has multiple people sitting at a table the event has multiple tickets which map the people to the tables that they are sitting at -> in order to achieve this I have created a checkbox nested in the fields_for :tables (which is in turn in the event form) I presume something is wrong with either the strong parameters or the form itself but I have not been able to find any information that provides a solution

Nested checkboxes in Rails

試著忘記壹切 提交于 2021-02-08 08:58:01
问题 I'm trying to create an event app where each event has multiple tables and each table has multiple people sitting at a table the event has multiple tickets which map the people to the tables that they are sitting at -> in order to achieve this I have created a checkbox nested in the fields_for :tables (which is in turn in the event form) I presume something is wrong with either the strong parameters or the form itself but I have not been able to find any information that provides a solution

Toggle “ActionController::Parameters.action_on_unpermitted_parameters = :raise” on specific controller methods?

陌路散爱 提交于 2021-01-28 04:31:33
问题 I want to use ActionController::Parameters.action_on_unpermitted_parameters = :raise To raise an exception unpermitted parameters are passed in, but I only want to do this on specific controller methods, instead of setting it in /config/ and having it apply to the whole environment. Is there any way to do so? 回答1: Update : (taking inspiration from Mike's answer) To restrict the change only for a set of controller actions and to revert it back to the original value that the class attribute was

Multiple require & permit strong parameters rails 4

◇◆丶佛笑我妖孽 提交于 2020-12-05 05:48:22
问题 In the below case, i am trying to use strong parameters. I want to require email_address, password and permit remember_me fields. But using like below it only allows the LAST line in the method Ex:- In below case it only take params.permit(:remember_me) private def registration_params params.require(:email_address) params.require(:password) params.permit(:remember_me) end Another Ex:- In this below case, if i rearrange it like below it will take only params.require(:email_address) where am i

Multiple require & permit strong parameters rails 4

百般思念 提交于 2020-12-05 05:44:11
问题 In the below case, i am trying to use strong parameters. I want to require email_address, password and permit remember_me fields. But using like below it only allows the LAST line in the method Ex:- In below case it only take params.permit(:remember_me) private def registration_params params.require(:email_address) params.require(:password) params.permit(:remember_me) end Another Ex:- In this below case, if i rearrange it like below it will take only params.require(:email_address) where am i

Multiple require & permit strong parameters rails 4

旧城冷巷雨未停 提交于 2020-12-05 05:44:05
问题 In the below case, i am trying to use strong parameters. I want to require email_address, password and permit remember_me fields. But using like below it only allows the LAST line in the method Ex:- In below case it only take params.permit(:remember_me) private def registration_params params.require(:email_address) params.require(:password) params.permit(:remember_me) end Another Ex:- In this below case, if i rearrange it like below it will take only params.require(:email_address) where am i

How to use strong parameters with an objects array in Rails

丶灬走出姿态 提交于 2020-04-10 08:18:08
问题 When using Rails 4.0 strong parameters, how do I permit JSON like this? { "user": { "first_name":"Jello" }, "users_to_employer":[ { "start_date":"2013-09-03T16:45:27+02:00", "end_date":"2013-09-10T16:45:27+02:00", "employer":{"company_name":"Telenor"} }, { "start_date":"2013-09-17T16:45:27+02:00", "end_date":null, "employer":{"company_name":"Erixon"} } ] } I tried: params.require(:users_to_employers => []).permit( :start_date, :end_date => nil, :employer => [ :company_name ]) But it didn't

How to permit hash with * key => values?

一个人想着一个人 提交于 2020-04-10 06:21:07
问题 I want to create an object with strong params that can accept dynamic hash keys. This is my code, Quiz.create(quiz_params) def quiz_params params.require(:quiz).permit(:user_id, :percent, :grade, questions: {}) end data that gets passed in would look something like this. // the keys that get passed into question is always different quiz: { user_id: 1, percent: 80, grade: "B", questions: { "12": "24", "1": "12", "4": "3", "5": "22" } } Currently however, when I try to create a Quiz, the

Rails 5 way to handle ActionController::ParameterMissing

柔情痞子 提交于 2020-03-05 05:00:03
问题 If a parameter that's required is missing using strong parameters, the Rails server will respond with an HTTP 500. This does not give me control over giving the user feedback with what exactly went wrong. Does it not make sense to be able to send them back a message such a required parameter is missing? What is the "Rails way" of giving appropriate user feedback on ActionController::ParameterMissing ? Is one supposed to capture the exception and handle your request response there? It seems

Rails 5 way to handle ActionController::ParameterMissing

眉间皱痕 提交于 2020-03-05 04:58:08
问题 If a parameter that's required is missing using strong parameters, the Rails server will respond with an HTTP 500. This does not give me control over giving the user feedback with what exactly went wrong. Does it not make sense to be able to send them back a message such a required parameter is missing? What is the "Rails way" of giving appropriate user feedback on ActionController::ParameterMissing ? Is one supposed to capture the exception and handle your request response there? It seems