Blank line break

Currently in my query model I have:

belongs_to :requestor, :class_name => 'User'

So the interrogator is current_user.

The problem is that he current_userclicks the Create button to submit the form for the request, all attributes are updated in the database on the form.
But since it is requestor_idnot a fill value in the form, which returns null in the database when creating a new query record.
I want an integer (which corresponds to the first key of the Users table) updated in a column requestor_idin the query table when the user clicks the create button.
So I thought that maybe adding requestor_idas a character in the parameters for the create action would solve the following:

def create_common
  @a = Request.new
    b = @a.requestor_id
  @resource = yield params[:contact + "#{b}".to_sym]
  self.resource = @resource

But instead, it returns the following error:

.

+3
4

, current_user Request?

# assign values passed in via form
@request = Request.new(params[:request])
# assign current_user to request
@request.requestor = current_user
# save the request
@request.save!

, !

0

. :

ruby-1.8.7-p174 :084 > a = 'fred'
 => "fred" 
ruby-1.8.7-p174 :085 > a.to_sym
 => :fred 
ruby-1.8.7-p174 :086 > a = ''
 => "" 
ruby-1.8.7-p174 :087 > a.to_sym
ArgumentError: interning empty string
    from (irb):87:in `to_sym'
    from (irb):87
+5

current_user ?

@req = Request.new(:requestor => current_user)

, yield params,

+2

"." , :

 errors.add('You entered a non-supported widget.')

" "

:

http://www.tonyamoyal.com/2009/10/20/interning-empty-string-error-in-ruby-on-rails/

Simple change:

 errors.add('You entered a non-supported widget')

fixed it. Rails 2.3.4 and Ruby 1.8.5

0
source

Source: https://habr.com/ru/post/1730716/


All Articles