I'm new to Rails. I'm using Service layer to keep my controllers thin. All 
my service layer files are located in app/services/domain, 
app/services/application and app/services/infrastructure. I'm using 
services in active admin controller section. When validation fail it can't 
redirect correctly, it keeps throwing me ActiveRecord::RecordInvalid. Here 
is the error page: 

<http://i.stack.imgur.com/YDiNN.png>

And here is the category service:

def self.create(params)
    ActiveRecord::Base.transaction do
        begin
            category = Category.new(params)
            decrease_counters(category.id)
            increase_counters(category.id)
                category.save!
        end
    end
end

In finally here is the my controller:

  controller do

    def create
      category = Service::CategoryService.create(params[:category])
      if category
        flash[:notice] = "Category was successfully created."
        redirect_to params[:button] == "create_and_new" ? 
new_admin_category_url : admin_categories_url
      else
        render active_admin_template('new.html.erb')
      end
    end
  end # end controller

How to solve it? Please help me.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/2RMlTx36pRAJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to