简体   繁体   中英

how to pass multiple parameter in render action in ruby on rails

my source code is

.modal-body
  =render 'folders/pieces/update', id: @piece , folder_id: @piece.folder_id

It throws an error:

undefined method 'folder_id' for nil:NilClass 

I want to pass two parameters in render page

Your code is valid and correct - it is exactly how you pass multiple params to render.

The error comes from the fact, that @piece is nil .

Your code is absolutely correct for multiple parameters. The error is because you are getting nil value in @piece . You can simply handle nil values as follows: @piece.try(:folder_id)

And your code will look something like:

.modal-body =render 'folders/pieces/update', id: @piece , folder_id: @piece.try(:folder_id)

This will not throw any error in case of nil value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM