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.