Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

better error handling for unsubscribe

  • Loading branch information...
commit a09d9ab285907d656df98a77930dd52d13f20c20 1 parent ba45e75
@zawaideh zawaideh authored
View
7 app/controllers/maktoub/subscribers_controller.rb
@@ -6,7 +6,12 @@ def edit
end
def update
- Maktoub.unsubscribe params[:email]
+ if params[:email].blank?
+ @message = "email is required"
+ render :edit, :status => 400
+ else
+ Maktoub.unsubscribe params[:email]
+ end
end
end
View
5 app/views/maktoub/subscribers/edit.html.erb
@@ -4,7 +4,10 @@
<p>
<%= label :subscribers, 'Email', :for => 'email' %>
<br/>
- <%= text_field :subscribers, 'email', {:type => "email", :id => 'email'} %>
+ <%- if @message %>
+ <div style="color:red;"><%= @message %></div>
+ <%- end %>
+ <%= text_field :subscribers, 'email', {:type => "email", :id => 'email', :name => 'email'} %>
<br />
</p>
<p>
View
5 spec/controllers/maktoub/subscribers_controller_spec.rb
@@ -39,5 +39,10 @@
put :update, :use_route => 'maktoub', :email => 'subscriber2@example.com'
response.should render_template 'subscribers/update'
end
+
+ it "should require an email" do
+ put :update, :use_route => 'maktoub'
+ response.status.should == 400
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.