I have a question.
The following error has occurred.
ArgumentError in Nutritions # index
Showing /Users/shotaro_hosoda/projects/berries/app/views/nutritions/index.html.erb where line # 32 raised:
wrong number of arguments (given 1, expected 2)
I presume that the part where this error is occurring is as follows.
[View file] index.html.erb
Omission
<% @ nutritions.each do | nutrition |%>
<tr height = "60">
<% if user_signed_in?%>
<% if current_user.already_favorited? (Nutrition)%>
<td><% = nutrition.ingredient%>
<% else%>
<td><% = nutrition.ingredient%>
<% end%>
<% else%>
<td><% = nutrition.ingredient%>
<% end%>
<ul>
<li>
<% if user_signed_in?%>
<% if current_user.already_favorited? (Nutrition, current_user)%>← Error part
<% = link_to'Release', nutrition_favorites_path (user_id: current_user.id, nutrition_id: nutrition.id, id: 0), method :: delete%>
<% else%>
<% = link_to'Registration', user_favorites_path (user_id: current_user.id, nutrition_id: nutrition.id), method :: post%>
<% end%>
<% = link_to'edit', edit_nutrition_path (nutrition.id), method:: get%>
<% = link_to'Delete', nutrition_path (nutrition.id), method:: delete, data: {confirm:'Are you sure I want to delete? '}%>
<% end%>
Omission
[Model] user.rb
#Include default devise modules. Others available are:
#: confirmable,: lockable,: timeoutable,: trackable and: omniauthable
devise: database_authenticatable,: registerable,
: recoverable,: rememberable,: validatable
has_many: nutritions
has_many: favorites, foreign_key: true, dependent:: destroy
has_many: fav_nutritions, through:: favorites, source:: nutrition
def already_favorited? (nutrition, current_user)
Favorite.exists? (User_id: current_user.id, nutrition_id: nutrition.id)
end
end
code
The already_favorite? method is called in the error part of the view.
At that time, two arguments (nutrition, current_user) are passed, and two formal arguments of the method are also defined (nutrition, current_user).
So why do we get the wrong number of arguments (given 1, expected 2)?
Since it says given1, does it mean that one of the (nutrition, current_user) at the time of calling is incorrect?
I would appreciate it if you could teach me.
-
Answer # 1
Related articles
- ruby on rails 5 - wrong number of arguments (given 0, expected 1) cannot be resolved
- ruby on rails - i want to resolve rails wrong number of arguments
- ruby - [rails] [asynchronous] like function: the number of likes is not displayed normally
- ruby on rails - [rails] how to specify the number of date_select to be displayed
- ruby on rails - i want to display the number of people in the group
- 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 - rspec of the like function how to get the number of likes or how to reflect by clicking the icon
- ruby on rails 6 - about validation (number of characters) of rails tweet posting
- ruby on rails - error when implementing rails6 follow function
- ruby on rails - i want to avoid displaying duplicate data for each shop
- ruby on rails - i want to deploy to aws ec2 server
- ruby on rails uninitialized constant error
- ruby on rails - i want to change from the state where only one posted image is displayed to the state where two posted images ar
- ruby on rails - description of rails packagejson
- ruby on rails 5 - the path is changed by redirect_to of rails
- ruby - rails: fattachment_field gives undefined method error
- ruby - unable to save comments in db (rails)
- ruby on rails - the value of find_by (id :) becomes nil
- python - you may need to restart the kernel to use updated packages error
- dart - flutter: the instance member'stars' can't be accessed in an initializer 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
- javascript - how to check if an element exists in puppeteer
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to check the type of a shell script variable
- i want to call a child component method from a parent in vuejs
The following has only one argument.