I'm trying to make a simple Tweet app.
I used scaffled when creating the posting function.
I want to make a list of individual posts for users
I want to add @ current_user.id (the ID of the person who posted) to the create method of the upload controller.
It may be difficult to convey with the first question.
I would appreciate it if you could answer.
It seems that the number of values sent and the number of values returned are different, but I don't know what to do.
Corresponding source code
ArgumentError in UploadsController # create wrong number of arguments (given 2, expected 0..1)
class UploadsController</pre> <strong>from viwe</strong> <pre><code><% = form_with (model: upload, local: true) do | form |%> <% if upload.errors.any?%> <% = pluralize (upload.errors.count, "error")%>prohibited this upload from being saved: <ul> <% upload.errors.full_messages.each do | message |%> <li><% = message%></li> <% end%> </ul> <% end%> <% = form.label: image%> <% = form.file_field: image%> <% = form.label: Name%> <% = form.text_field: title%> <% = form.label: Price%> <% = form.text_field: body%> <% = form.submit%> <% end%>
Please describe here what you have tried for the problem.
from<% = form_with (model: upload, local: true) do | form |%>to<% = form_tag>
I described it withand described the reception of the create method as Upload.new (title: params [: title]), but it didn't work.
Answer # 1
I thought it was appropriate to add current_user.id to upload_params while doing the following here
@upload = Upload.new (upload_params)
def upload_params params.require (: upload) .permit (: image,: title,: body) .merge (user_id: @ current_user.id) end
I'm adding @ current_user.id to upload_params with merge (I don't know where @current_user is defined, but I borrowed it from the question)
This is an old article, but this may be helpful for merge.
In the merge method, save the information that you have in another table in advance together with the entered params.
- ruby on rails - dealing with wrong number of arguments (given 1, expected 2)
- ruby on rails 5 - wrong number of arguments (given 0, expected 1) cannot be resolved
- i want to resolve the error statement (ruby on rails)
- ruby on rails 6 - about rails error "wrong number of arguments (given 1, expected 0)"
- ruby on rails - get results in argumenterror (wrong number of arguments (given 1, expected 0)):
- ruby on rails - [rails] i want to know how to resolve activerecord :: recordnotfound errors
- ruby - [rails] unable to resolve "name error in affiliates controller # show" error
- ruby on rails - [rails] how to specify the number of date_select to be displayed
- ruby - migrations are pending in rails s to resolve this issue, run: rails db: migrate rails_env = development
- ruby - [rails] [asynchronous] like function: the number of likes is not displayed normally
- ruby on rails - i want to resolve rails name error
- ruby on rails - rspec of the like function how to get the number of likes or how to reflect by clicking the icon
- ruby on rails - how to resolve lib/rack/session/abstract/idrb: 375: in'commit_sesion' that occurs in rspec
- ruby - [rails] how to resolve activerecord errors
- ruby on rails - i want to display the number of people in the group
- ruby on rails 6 - about validation (number of characters) of rails tweet posting
- ruby on rails - i want to resolve rails nameerror
- ruby - rails unable to resolve user errors
- ruby on rails - i want to resolve a routing error
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to call a child component method from a parent in vuejs
- python 3x - typeerror: 'method' object is not subscriptable