Note that there are some explanatory texts on larger screens.

plurals
  1. POrails devise user external api
    primarykey
    data
    text
    <p>I am trying to setup a newsletter signup procedure when a new user signs up. I am using Mailchimp via gibbon to handle the newsletters. I have added a subscribe attribute to my model and a getter and setter method. I also have added the subscribe checkbox to my form. What I need to do is if the form box is checked subscribe the user to the email on creation. </p> <p>model </p> <pre><code>class User &lt; 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 =&gt; "blah", :email_address =&gt; self.email) end end def subscribe subscribe ||= false end end </code></pre> <p>Form view</p> <pre><code>&lt;h2&gt;Sign up&lt;/h2&gt; &lt;%= form_for(resource, :as =&gt; resource_name, :url =&gt; registration_path(resource_name)) do |f| %&gt; &lt;%= devise_error_messages! %&gt; &lt;p&gt;&lt;%= f.label :username %&gt;&lt;br /&gt; &lt;%= f.text_field :username %&gt;&lt;/p&gt; &lt;div&gt;&lt;%= f.label :email %&gt;&lt;br /&gt; &lt;%= f.email_field :email %&gt;&lt;/div&gt; &lt;div&gt;&lt;%= f.label :password %&gt;&lt;br /&gt; &lt;%= f.password_field :password %&gt;&lt;/div&gt; &lt;div&gt;&lt;%= f.label :password_confirmation %&gt;&lt;br /&gt; &lt;%= f.password_field :password_confirmation %&gt;&lt;/div&gt; &lt;div&gt;&lt;%= f.label :subscribe, "Subscribe to Newsletter?" %&gt;&lt;br /&gt; &lt;%= f.check_box :subscribe, :checked =&gt; true %&gt;&lt;/div&gt; &lt;div&gt;&lt;%= f.submit "Sign up" %&gt;&lt;/div&gt; &lt;% end %&gt; &lt;%= render "devise/shared/links" %&gt; </code></pre> <p>I was hoping that by adding the attr_accessible and a method it would call the api from the contoller automatically, but it does not seem to be called.</p> <p>Any advice on how to handle this? I could also use advice on how to test with RSPEC to make sure it is being called.</p> <p>Thanks, Cory</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload