我在Messages#new中收到了ArgumentError app / views / messages / new.html.erb第16行引发: “错误的参数数量(2对1)” 它还说:
app / helpers / application_helper.rb:8:在recipients_options中的avatar_url'
app/helpers/messages_helper.rb:5:in
块中
app / helpers / messages_helper.rb:4:{_ 1}}块中的_app_views_messages_new_html_erb___264831154_80406348'
app / views / messages / new.html.erb:3:in`_app_views_messages_new_html_erb ___ 264831154_80406348'
我的申请助手:
recipients_options'
app/views/messages/new.html.erb:16:in
我的消息助手是,
module ApplicationHelper
def page_header(text)
content_for(:page_header) { text.to_s }
end
def avatar_url(user)
if user.image
user.image
else
"/images/missing.png"
end
end
end
我的消息/ new.html.erb是,
module MessagesHelper
def recipients_options(chosen_recipient = nil)
s = ''
User.all.each do |user|
s << "<option value='#{user.id}' data-img-src='#{image_tag avatar_url(user.email, size: 50)}' #{'selected' if user == chosen_recipient}>#{user.name}</option>"
end
s.html_safe
end
end
messages_controller.rb
<% page_header "Start Conversation" %>
<%= form_tag messages_path, method: :post do %>
<div class="form-group">
<%= label_tag 'message[subject]', 'Subject' %>
<%= text_field_tag 'message[subject]', nil, class: 'form-control', required: true %>
</div>
<div class="form-group">
<%= label_tag 'message[body]', 'Message' %>
<%= text_area_tag 'message[body]', nil, cols: 3, class: 'form-control', required: true %>
</div>
<div class="form-group">
<%= label_tag 'recipients', 'Choose recipients' %>
<%= select_tag 'recipients', recipients_options(@chosen_recipient), multiple: true, class: 'form-control chosen-it' %>
</div>
<%= submit_tag 'Send', class: 'btn btn-primary' %>
<% end %>
答案 0 :(得分:2)
在#{image_tag avatar_url(user.email, size: 50)}
下,您传递了两个参数,但def avatar_url(user)
只接受一个参数。
答案 1 :(得分:1)
您定义了avatar_url
,其中包含一个参数,但您正在传递两个参数
avatar_url(user.email, size: 50)