strong-parameters

RSpec - Testing Strong Parameters ActionController::ParameterMissing

喜欢而已 提交于 2019-12-08 03:15:13
问题 How can one test if a certain action raises an ActionController::ParameterMissing exception? For example: it "raises an exception" do post :create, {} expect(response).to raise ActionController::ParameterMissing end The above does not seem to work, it will fail the test with the ActionController::ParameterMissing exception. 回答1: Use the expect block syntax using the raise_error matcher: it "raises an exception" do expect{ post(:create, {}) }.to raise_error ActionController::ParameterMissing

rails 4 has_many :through not saving associations

旧街凉风 提交于 2019-12-07 16:10:20
问题 I have 2 models with many to many association as follows: class User < ActiveRecord::Base has_many :remark_users, :dependent => :destroy has_many :designated_remarks, :through => :remark_users, :source => :remark end class Remark < ActiveRecord::Base has_many :remark_users, :dependent => :destroy has_many :users, :through => :remark_users accepts_nested_attributes_for :users end And the relationship: class RemarkUser < ActiveRecord::Base belongs_to :remark belongs_to :user end The remarks

How to use Rails Action Controller Nested Params to Permit a Specific Attributes Hash

十年热恋 提交于 2019-12-07 09:03:23
问题 There are a lot of questions about Nested Parameters, but I can't seem to find one that addresses my specific, simple situation. I'm trying to permit a nested hash that is NOT an array. I expected this to work: params.require(:book).permit(:title, :description, style: {:font, :color}) But it resulted in a syntax error. This, however, worked: params.require(:book).permit(:title, :description, style: [:font, :color]) But my issue with this, it it seems to permit style values that are arrays of

Can't Save Image Attributes with Paperclip in Rails 4

社会主义新天地 提交于 2019-12-07 08:27:08
问题 I have two associated models in my Rails 4 app: product.rb and image.rb . The Image model allows attached files using the Paperclip gem. Images belong_to a Product, and a product has_many Images. I would like to use the Product's new view to create and attach an image when I create a product. Each time I try, the parameters associated with the Paperclip image do not get saved, and end up nil . Here are the models: Product.rb class Product < ActiveRecord::Base validates :name, :part_number,

whitelisting deeply nested strong parameters in rails

≯℡__Kan透↙ 提交于 2019-12-06 15:23:12
问题 I'm trying to store a serialized Ransack search in a text column. It's deeply nested and I'm struggling coming up with permit call for it. Here's a sample hash: { "c"=>{ "0"=>{ "a"=>{ "0"=>{ "name"=>"column_1" } }, "p"=>"eq", "v"=>{ "0"=>{ "value"=>"value_1" } } }, "1"=>{ "a"=>{ "0"=>{ "name"=>"column_2" } }, "p"=>"cont", "v"=>{ "0"=>{ "value"=>"value_2" } } } } } How would you write a permit for that? This is my best guess for reading the doc but it isn't working. def course_listing_params

Ruby on Rails: Can't implement Star Rating system

痞子三分冷 提交于 2019-12-06 14:24:14
问题 I'm trying to add a simple Star Rating system for my app having taken this tutorial for an example. I have User, Hotel and Rating models. Dependencies are: (rating.rb) belongs_to :user belongs_to :hotel (hotel.rb) & (user.rb) has_many :ratings And with the following code in hotel view I get this error: NameError in Hotels#show undefined local variable or method `user' for Class... (in the line with <%= form_for ...) Hotel view (show.html.erb): <% form_id = "hotel_#{@hotel.id}_rating" %> <% if

ActionController::ParameterMissing param is missing or the value is empty

不问归期 提交于 2019-12-06 13:08:32
问题 I can't solve this problem. When I try to use "Chatroom#new" method, I I got this error, ActionController::ParameterMissing param is missing or the value is empty . below codes are the ChatroomController. class ChatroomsController < ApplicationController before_action :find_room_owner,only:[:index] before_action :objects_for_index,only:[:index] def index #/users/:user_id/cart/items/chatroom sign_in @user if signed_in? if @seller && @buyer flash[:success] = "U are owners of the chatroom"

Rails 4, strong parameters, nested resources, build and undefined method permit

醉酒当歌 提交于 2019-12-06 11:21:53
问题 I am unable to get rails 4, strong parameters to work with nested resources via build. Any suggestions would be very welcome. RSPEC shows me Creating Actions Creating an action Failure/Error: click_button "Create Action" NoMethodError: undefined method permit' for "create":String # ./app/controllers/actions_controller.rb:24:in action_params' # ./app/controllers/actions_controller.rb:10:in create' # ./spec/features/creating_actions_spec.rb:16:in block (2 levels) in ' My Browser shows me:

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

你说的曾经没有我的故事 提交于 2019-12-06 08:36:53
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:0x0000010652d3c8 @tempfile=#<Tempfile:/var/folders/0f/hgplttnd7dg6q9m62qtbnpn00000gn/T

Getting Started With Rails Tutorial: 5.7 Showing posts — No Forbidden Attributes Error

谁都会走 提交于 2019-12-06 06:33:02
问题 I've been following this Rails tutorial: http://guides.rubyonrails.org/getting_started.html Section 5.7 tells me that I should expect an ActiveModel::ForbiddenAttributesError The thing is, I don't get the error. It works without the permit keyword. My create method looks like this: def create @post = Post.new(post_params) @post.save redirect_to @post end I'm working with Rails 4.0 and Ruby 2.0. Any idea why the strong parameters security function isn't working? 回答1: The documentation is