【发布时间】:2016-10-17 18:47:08
【问题描述】:
我正在尝试弄清楚如何遵循本教程中的想法:
https://coderwall.com/p/rqjjca/creating-a-scoped-invitation-system-for-rails
我不知道如何邀请用户。我有一个表单来邀请在显示页面上工作的用户。它一直有效到我按下发送。然后我收到一条错误消息:
wrong number of arguments (given 1, expected 0)
我不知道参数是什么。我不确定被称为给定参数的一件事是什么,我不知道系统期望什么。我一直在试图弄清楚一个论点是什么,以及我是否需要试图弄清楚如何增加期望或减少已经给出的被计算的东西。
我发现这篇文章试图解释什么是参数:http://www.skorks.com/2009/08/method-arguments-in-ruby/ 但在给出的所有示例中,它没有显示没有参数的方法,它实际上并没有说明参数是做什么的.我还是一头雾水。
错误消息中的引用是:
def existing_user_invite
mail(
:subject => "You've been invited to join a team",
:to => 'hello@you.com',
:from => 'me@you.com',
:html_body => ''
# :track_opens => 'true'
)
end
在我的邀请创建操作中也引用了这一行:
def create
@invite = Invite.new(invite_params)
@invite.sender_id = current_user.profile.id
if @invite.save
InviteMailer.existing_user_invite(@invite).deliver
@invite.recipient.project.push(@invite.project)
else
#send new user email invitation to join as a user and then as part of this team
@invite.recipient.project.push(@invite.project)
# InviteMailer.new_user_invite(@invite, new_user_registration_path(:invite_token => @invite.token)).deliver
end
# oh no, creating an new invitation failed
end
教程创建方法显示如下:
def create
@invite = Invite.new(invite_params)
@invite.sender_id = current_user.id
if @invite.save
#if the user already exists
if @invite.recipient != nil
#send a notification email
InviteMailer.existing_user_invite(@invite).deliver
#Add the user to the user group
@invite.recipient.user_groups.push(@invite.user_group)
else
InviteMailer.new_user_invite(@invite, new_user_registration_path(:invite_token => @invite.token)).deliver
end
else
# oh no, creating an new invitation failed
end
end
我发现通常很难找到解释什么是组件的 rails 或 ruby 资源。我正在固定我之前的问题,以提供有关我正在尝试解决的问题的更多背景信息:
Rails 4 - Invite team mates to project
Rails 4 - Associations - adding team mates to teams
Invite_mailer.rb
class InviteMailer < ActionMailer::Base
# include Devise::Mailers::Helpers
def existing_user_invite(invite)
mail(
:subject => "You've been invited to join a research project team",
:to => 'hello@you.com',
:from => 'me@you.com',
:html_body => ''
# :track_opens => 'true'
)
end
end
【问题讨论】:
标签: ruby-on-rails ruby methods arguments