2013-02-13 2 views
0

새 사용자가 가입 할 때 뉴스 레터 가입 절차를 설정하려고합니다. 나는 긴팔 원숭이를 통해 Mailchimp를 사용하여 뉴스 레터를 처리하고 있습니다. 내 모델 및 getter 및 setter 메서드에 subscribe 특성을 추가했습니다. 또한 양식에 구독 체크 박스를 추가했습니다. 내가해야 할 일은 양식 상자가 선택되어 생성시 전자 메일에 사용자를 가입시키는 것입니다. rails 사용자 외부 api

class User < ActiveRecord::Base 
    # Include default devise modules. Others available are: 
    # :token_authenticatable, :confirmable, 
    # :lockable, :timeoutable and :omniauthable 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 



    # Setup accessible (or protected) attributes for your model 
    attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :subscribe 

    validates :username, presence: true 
    validates_uniqueness_of :username 

    has_many :contest_entries, dependent: :destroy 
    has_many :votes, dependent: :destroy 

    def subscribe=(join) 
    puts "called subscribe with #{join}" 
    if join 
     Gibbon.new.list_subscribe(:id => "blah", :email_address => self.email) 
    end 
    end 

    def subscribe 
    subscribe ||= false 
    end 

end 

이 폼보기는

<h2>Sign up</h2> 

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> 
    <%= devise_error_messages! %> 

    <p><%= f.label :username %><br /> 
    <%= f.text_field :username %></p> 

    <div><%= f.label :email %><br /> 
    <%= f.email_field :email %></div> 

    <div><%= f.label :password %><br /> 
    <%= f.password_field :password %></div> 

    <div><%= f.label :password_confirmation %><br /> 
    <%= f.password_field :password_confirmation %></div> 

    <div><%= f.label :subscribe, "Subscribe to Newsletter?" %><br /> 
    <%= f.check_box :subscribe, :checked => true %></div> 

    <div><%= f.submit "Sign up" %></div> 
<% end %> 

<%= render "devise/shared/links" %> 
나는 attr_accessible과 방법을 추가하여 자동으로 콘트롤에서 API를 호출 할 것이라고 기대했다, 그러나 보이지 않는다

호출 할

모델 .

처리 방법에 대한 조언이 있으십니까? RSPEC을 테스트하여 RSPEC이 호출되는지 확인하는 방법에 대한 조언도 사용할 수 있습니다.

감사합니다, 코리

답변

0

확인 나는이 문제를 알아 냈어. 문제는 setter 메소드 내부의 조인 확인 때문입니다. 이 체크 박스 이었기 때문에, 나는 1

def subscribe=(join) 
begin 
    if join.to_i == 1 
    gb = Gibbon.new 
    result = gb.list_subscribe(:id => "blah", :email_address => self.email) 
    end 
rescue 
    false 
end 

의 일치 정수를 확인하기 위해 필요