2016-06-16 2 views
-1

을 범위. 쇼 페이지에서 일하는 사용자를 초대하는 양식이 있습니다. 그것은 내가 보내기를 누르는 지점까지 작동합니다. 그런 다음 오류 메시지가 표시됩니다.레일 4 - - 인수 오류가 나는이 튜토리얼의 아이디어를 함께 따라하는 방법을 알아 내려고 노력하고있어 초대

wrong number of arguments (given 1, expected 0) 

나는 인수가 무엇인지 알지 못합니다. 한 가지가 주어진 인수로 불리는 것이 무엇인지 확실하지 않으며 시스템에서 예상하는 내용을 알지 못합니다. 나는 논쟁이 무엇인지, 그리고 기대를 높이는 방법을 찾아 내거나 계산되는 것을 줄이기 위해 노력해야 하는지를 알아 내려고 노력해 왔습니다.

나는 인수가 무엇인지 설명하려고하는이 기사를 발견했습니다 : http://www.skorks.com/2009/08/method-arguments-in-ruby/ 그러나 주어진 모든 예제 중, 인수없이 메소드를 표시하지 않으며 인수가 실제로 무엇인지 말하지 않습니다. 나는 아직도 혼란 스럽다.

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 
: 메소드를 생성

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 existing_user_invite 
    mail(
     :subject => "You've been invited to join a team", 
     :to => '[email protected]', 
     :from => '[email protected]', 
     :html_body => '' 
     # :track_opens => 'true' 
    ) 
    end 

:에 오류 메시지에서

참고 문헌은

일반적으로 구성 요소가 무엇인지 설명하는 레일이나 루비 리소스를 찾는 것이 어렵다는 것을 알고 있습니다.

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 => '[email protected]', 
     :from => '[email protected]', 
     :html_body => '' 
     # :track_opens => 'true' 
    ) 
    end 
end 

답변

0

잘못된 번호 : 내가 해결하기 위해 노력하고있어 문제에 대한 자세한 배경을 제공하기 위해 내 이전 질문에, 고정 해요 인수 중 (주어진 1, 예상 0)

existing_user_invite이 있는데 은 아무런 인자도 기대하지 않지만 existing_user_invite(@invite)을 전달합니다. 해당 메서드에 인수를 전달하려면 인수를 허용하도록 인수를 변경해야합니다.

def existing_user_invite(invite) 
    mail(
    :subject => "You've been invited to join a team", 
    :to => '[email protected]', 
    :from => '[email protected]', 
    :html_body => '' 
    # :track_opens => 'true' 
) 
end 
+0

안녕하세요, Pavan, 이것을 시도했지만 "stack level too deep"오류가 발생합니다. 내가 해독 할 수있는 것으로부터, 코드가 루프에 갇혀 있기 때문에 에러가 발생한다 : 메소드 자체를 호출하는 메소드 또는 서로를 반복적으로 호출하는 두 메소드. 나는 그것이 의미하는 바가 무엇인지, 또는 논점을 추가함으로써 어떻게 될 수 있는지를 모른다. 나는 그 다음에 대해 더 많은 것을 배우려고 노력할 것이다. – Mel

+0

@Mel은 그것을 기대하지 않았습니다. 'def existing_user_invite (invitation)' – Pavan

+0

과 같은 인수 이름을 다른 것으로 변경해 볼 수 있습니까? (초대장)의 의미는 무엇입니까? 내가 삽입해야 할 단어가 임의적입니까? – Mel

0

는 파반의 대답은 첫 번째 오류

wrong number of arguments (given 1, expected 0)

그리고 두 번째 질문은, 왜 점점됩니다지고 이유를 설명 @ 내 생각은 existing_user_invite 방법에있는 stack level too deep

잘못된 수업.그래서

#app/mailers/invite_mailer.rb 
class InviteMailer < ApplicationMailer 

    # there may be other methods in this class too 

    def existing_user_invite(invite) 
    mail(
     :subject => "You've been invited to join a team", 
     :to => '[email protected]', 
     :from => '[email protected]', 
     :html_body => '' 
     # :track_opens => 'true' 
    ) 
    end 
end 

existing_user_invite 방법은 u는 컨트롤러에서 통과 r에 1 개 인자 (초대)를 가지고 있습니다하려고 당신은 Invite 모델을 가지고있을 수 있습니다,하지만 정말 InviteMailer

로 이동합니다. (@ Pavan 언급 된대로)

그러나 여전히 문제가있는 경우 전체 트랙 추적 오류를 게시하여 문제를 쉽게 찾을 수 있도록하십시오. :)

+0

안녕 샘, 정말 고마워. 그러나 existing_user_invite (invite)는 invite_mailer.rb 파일에 있습니다. – Mel

관련 문제