strong-parameters

Ruby on Rails: Can't implement Star Rating system

血红的双手。 提交于 2019-12-04 19:57:46
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 signed_in? %> <!-- To avoid throwing an exception if no user is signed in --> <% user_id = current

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

安稳与你 提交于 2019-12-04 19:52:54
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" @messages = Message.all #Messageのmodelを作成 else flash[:error] = "U cant enter the chatroom." redirect_to user

Why slicing the params hash poses a security issue on mass-assignment?

醉酒当歌 提交于 2019-12-04 17:40:27
问题 The official way of preventing security risks with mass-assignment is using attr_accessible. However, some programmers feel this is not a job for the model (or at least not only for the model). The simplest way of doing it in a controller is slicing the params hash: @user = User.update_attributes(params[:user].slice(:name)) However the documentation states: Note that using Hash#except or Hash#slice in place of attr_accessible to sanitize attributes won’t provide sufficient protection. Why is

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

谁说我不能喝 提交于 2019-12-04 16:43:50
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: NoMethodError in ActionsController#create undefined method `permit' for "create":String Extracted source

Rails 4 Strong Params has_many with JSON

。_饼干妹妹 提交于 2019-12-04 15:57:08
问题 I'm attempting to pass json up on the client side and have rails take care of handling the object creation. Here are my models: class Order < ActiveRecord::Base has_many :order_items, :autosave => true belongs_to :menu_session end class OrderItem < ActiveRecord::Base belongs_to :order has_one :menu_item end Controller class OrderController < ApplicationController #POST /order/create def create @order = Order.new(order_params) @order.save end private def order_params params.require(:order)

has_one nested attributes not saving

可紊 提交于 2019-12-04 13:34:53
I have two models Project and ProjectPipeline. I want to create a Project form that also has fields from the ProjectPipeline model. I have created the form successfully but when I hit save the values aren't stored on the database. project.rb class Project < ActiveRecord::Base has_one :project_pipeline accepts_nested_attributes_for :project_pipeline self.primary_key = :project_id end projectpipeline.rb class ProjectPipeline < ActiveRecord::Base belongs_to :project, autosave: :true validates_uniqueness_of :project_id end I don't always want a project pipeline but under the right conditions based

Rails 4 - strong parameters concept involvement in spree-2.1

核能气质少年 提交于 2019-12-04 12:09:20
问题 How to add new fields for spree::user in Spree-2.1 + Rails4 ? Like my old customization: ========================== Spree::User.class_eval do attr_accessible :f_name, :l_name :gender validates :f_name, :presence => true, :length => {:maximum => 25} validates :l_name, :presence => true, :length => {:maximum => 20} end new work with strong parameters: ================================ module Spree UserRegistrationsController.class_eval do private def spree_user_params params.require(:spree_user)

Permit extra params in special cases with Strong Params in Rails 4

空扰寡人 提交于 2019-12-04 11:11:27
So for an organization, I want users to be able to be able to edit some things about it. params.require(:organization).permit(:name, :location) But in special cases, I want administrators to be able to edit extra attributes params.require(:organization).permit(:name, :location, :secrets) Now I know I can just have an if statement to choose which line I want to use, but since the admin will always be able to edit the original attributes, I wanted to easily be able to include them like so: permitted = params.require(:organization).permit(:name, :location) permitted.permit(:secrets) if current

Strong parameters and multidimensional arrays

…衆ロ難τιáo~ 提交于 2019-12-04 06:21:24
I'm using Rails 3.2.6 with strong parameters gem. So, I' have a controller with the typical update action: # PUT /api/resources/:id def update @resource.update_attributes! permited_params respond_with_json @resource, action: :show end Then, I have the permited_params method def permited_params params.permit(:attr1, :attr2, :attr3) end The problem is that :attr3 is a multidimensional array like this: [[1, 2], [2, 5, 7]] Following the documentation, I need to specify :attr3 as an array. But... params.permit(:attr1, :attr2, :attr3 => []) #inspecting permited_params: {"attr1"=>"blah", "attr2"=>

Rails: Merging a nested attribute with strong_params

南笙酒味 提交于 2019-12-04 01:28:59
In Rails 4, it's possible to merge extra parameters with user generated ones like so: params.require(:post).permit([:title, :body]).merge(user: current_user) It's also possible to include nested attributes like so: params.require(:post).permit([:title, :body, sections_attributes: [:title, :section_type]]) Now, what if I wanted to merge extra parameters into a nested model. I tried this: params.require(:post).permit([:title, :body, sections_attributes: [:title, :section_type]]).merge(user: current_user, sections_attributes: [user: current_user]) But when I check the params with debugger