strong-parameters

Do we need to permit ruby virtual attributes also?

天大地大妈咪最大 提交于 2020-01-25 03:17:20
问题 Till now I thought, I have to permit only those attributes which I required to save in database. But recently I used Jcrop to crop my User avatar and it has 4 virtual attributes which will be sent after crop from the front end, Here is my model class User < ActiveRecord::Base mount_uploader :avatar, AvatarUploader attr_accessor :crop_x, :crop_y, :crop_w, :crop_h after_update :crop_avatar def crop_avatar avatar.recreate_versions! if crop_x.present? end end When I submit after crop, my console

Do we need to permit ruby virtual attributes also?

狂风中的少年 提交于 2020-01-25 03:17:15
问题 Till now I thought, I have to permit only those attributes which I required to save in database. But recently I used Jcrop to crop my User avatar and it has 4 virtual attributes which will be sent after crop from the front end, Here is my model class User < ActiveRecord::Base mount_uploader :avatar, AvatarUploader attr_accessor :crop_x, :crop_y, :crop_w, :crop_h after_update :crop_avatar def crop_avatar avatar.recreate_versions! if crop_x.present? end end When I submit after crop, my console

Strong parameters with has_many gives “no implicit conversion of Symbol into Integer”

只谈情不闲聊 提交于 2020-01-16 01:26:44
问题 Trying to create a user from a json request but my server gives me "typeError (no implicit conversion of Symbol into Integer)". I understand that it's something wrong with my nested attribute but i dont know what, this's driving me crazy.. My Javascript file: user = { email: @get('email') first_name: @get('firstName') last_name: @get('lastName') password: @get('password') password_confirmation: @get('passwordConfirmation') registration_completed: true authentications_attributes: { provider:

Accessing Custom Parameters when using Devise and Rails 4

岁酱吖の 提交于 2020-01-11 04:08:05
问题 I am learning rails using the teamtreehouse tutorial. The tutorial uses 3.1 but I am trying to learn 4.0, and as a result I have run into a difficulty presumably because rails 4 forces of the use of strong parameters. I have two models, a users model and a statuses model. I have used devise to create authentication for users, and have included new parameters. They are :first_name, :last_name, and :profile_name. I have created a relationship between users and statuses. Currently the user sign

Rails 4.1.5 omniauth strong parameters

半城伤御伤魂 提交于 2020-01-09 09:02:56
问题 After upgrading Rails 4.1.4 to 4.1.5 i get errors with my facebook omniauth session everything was working fine since then. When i create a User Session i get an ActiveModel::ForbiddenAttributesError Route: match 'auth/:provider/callback', to: 'sessions#create', as: 'signin', via: :get Session#create controller: def create user = User.from_omniauth(env["omniauth.auth"]) session[:user_id] = user.id session[:user_name] = user.name redirect_to root_path end and a user model like this: def self

undefined method `model_name_question' for #..Rails 4

风格不统一 提交于 2020-01-06 06:45:42
问题 I am getting this error after submitting the form:(in the index page) <%= simple_form_for(@quiz, html: {class: 'form-vertical' }) do |f| %> <%= render 'shared/error_messages_question' %> <%= f.input_field :content, :rows => 3, :style => "width:80%", :placeholder => "enter your question." %> <%= f.button :submit %> <% end %> I have question model: class Question < ActiveRecord::Base validates :question, presence: true belongs_to :category belongs_to :questioner end and questions controller:

Rails 4 Strong Parameters Nested Resource

℡╲_俬逩灬. 提交于 2020-01-04 13:46:43
问题 I have a nested resource like the following: user/1/photos/new resources :users, only: [] do resources :photos, except: [:show] end My form_for is like the following: = form_for([@user, @photo], html: { multipart: true }) do |f| .inputs = f.file_field :attached_photo .actions = f.submit :submit I believe the problem I am having is with strong parameters: def photo_params params.require(:photo).permit(:title, :attached_photo) end When I hit the submit button on the form I get the following

Creating two objects in Rails 4 controller with strong_params

别来无恙 提交于 2020-01-04 11:40:11
问题 In my Rails 4 Controller action, I'm passing the following params: {"user"=>{"email"=>"", "password"=>"[FILTERED]", "profile"=>{"birthday"=>nil, "gender"=>nil, "location"=>"", "name"=>""}}} Now from those params I'm hoping to create two objects: User and its Profile . I've tried iterations of the following code but can't get passed strong_params issues: def create user = User.new(user_params) profile = user.build_profile(profile_params) ... end private def user_params params.require(:user)

Stack Level Too Deep error - produced with strong parameters I think

折月煮酒 提交于 2020-01-02 10:59:46
问题 I think the issue could be strong parameters in Rails 4, but I am not sure. Here is what I have. All I am trying to do is create a post , but when it gets submitted I get this error: Started POST "/posts" for 127.0.0.1 at 2014-08-28 06:06:57 -0500 Processing by PostsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"daURJjzq2EMfiQZ/uiD/0ADg=", "post"=>{"status"=>"confirmed", "title"=>"Ashlee lost 10 pounds in 5 weeks", "photo"=>#<ActionDispatch::Http::UploadedFile

rails 4 with link_to and method post with strong parameters

和自甴很熟 提交于 2020-01-02 04:44:06
问题 I'm stuck in a problem which can't be that complicated, but I'm just not getting things right. Assuming I've got two Models: class Notification < ActiveRecord::Base belongs_to :device validates :number, presence: true end and class Device < ActiveRecord::Base belongs_to :user has_many :notifications, :dependent => :destroy //rest omitted for brevity end with nested routes like so: resources :devices do resources :notifications end and a notifications controller like so: class