diff --git a/app/controllers/tag_subscriptions_controller.rb b/app/controllers/tag_subscriptions_controller.rb index e8f19c2af..425954b75 100644 --- a/app/controllers/tag_subscriptions_controller.rb +++ b/app/controllers/tag_subscriptions_controller.rb @@ -23,14 +23,30 @@ class TagSubscriptionsController < ApplicationController def create @tag_subscription = TagSubscription.create(params[:tag_subscription]) - respond_with(@tag_subscription, :location => tag_subscriptions_path) + respond_with(@tag_subscription) do |format| + format.html do + if @tag_subscription.errors.any? + render :action => "new" + else + redirect_to tag_subscriptions_path + end + end + end end def update @tag_subscription = TagSubscription.find(params[:id]) check_privilege(@tag_subscription) @tag_subscription.update_attributes(params[:tag_subscription]) - respond_with(@tag_subscription, :location => tag_subscriptions_path) + respond_with(@tag_subscription) do |format| + format.html do + if @tag_subscription.errors.any? + render :action => "edit" + else + redirect_to tag_subscriptions_path + end + end + end end def destroy diff --git a/app/models/tag_subscription.rb b/app/models/tag_subscription.rb index 7acae058c..420d921db 100644 --- a/app/models/tag_subscription.rb +++ b/app/models/tag_subscription.rb @@ -6,6 +6,7 @@ class TagSubscription < ActiveRecord::Base before_save :limit_tag_count attr_accessible :name, :tag_query, :post_ids, :is_public, :is_visible_on_profile validates_presence_of :name, :tag_query, :creator_id + validates_format_of :tag_query, :with => /^(?:\S+\s*){1,20}$/, :message => "can have up to 20 tags" validate :creator_can_create_subscriptions, :on => :create def normalize_name @@ -26,7 +27,7 @@ class TagSubscription < ActiveRecord::Base def creator_can_create_subscriptions if TagSubscription.owned_by(creator).count >= Danbooru.config.max_tag_subscriptions - self.errors.add(:creator, "can subscribe up to #{Danbooru.config.max_tag_subscriptions} tags") + self.errors.add(:creator, "can create up to #{Danbooru.config.max_tag_subscriptions} tag subscriptions") return false else return true @@ -38,7 +39,7 @@ class TagSubscription < ActiveRecord::Base end def limit_tag_count - self.tag_query = tag_query_array.slice(0, 20).join(" ") + # self.tag_query = tag_query_array.slice(0, 20).join(" ") end def process diff --git a/app/views/tag_subscriptions/_form.html.erb b/app/views/tag_subscriptions/_form.html.erb index 19ae01ec4..e5775b574 100644 --- a/app/views/tag_subscriptions/_form.html.erb +++ b/app/views/tag_subscriptions/_form.html.erb @@ -7,5 +7,5 @@ Is Public - <%= f.button :submit %> + <%= f.button :submit, "Submit" %> <% end %> diff --git a/app/views/tag_subscriptions/edit.html.erb b/app/views/tag_subscriptions/edit.html.erb index 93babace3..a5c3d39c3 100644 --- a/app/views/tag_subscriptions/edit.html.erb +++ b/app/views/tag_subscriptions/edit.html.erb @@ -1,6 +1,9 @@