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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Tyler at May 15, 2012 at 10:04 pm
    This all seems very unnecessary. Have you tried pushing the business logic
    into the Category model instead?

    Best thing with Rails is to follow convention (that is kind of the point of
    Rails). You can go through www.railstutorial.org and get a much better
    sense for how to structure your controllers and models.
    On Tuesday, May 15, 2012 9:17:00 AM UTC-7, Zeck wrote:

    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/-/p8zG1aRSQh0J.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMay 15, '12 at 4:17p
activeMay 15, '12 at 10:04p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Tyler: 1 post Zeck: 1 post

People

Translate

site design / logo © 2021 Grokbase