Question

I googled for a long time, but didn't find full answer for my problem.

In my app I use inherited_resources. So, I want to override redirect after succefull creation of Comment object, so I write:

update! do |success, failure|
  success.html { redirect_to parent_url }
end

I know that I could do it in one string, but I need block, because I need to add actions when failure happens too. So I write:

update! do |success, failure|
  success.html { redirect_to parent_url }
  failure.html { 
    add_breadcrumb t("share.Home"), root_path
    add_breadcrumb t("project.Projects"), projects_path
    ...
    add_breadcrumb t("comment.edit_comment"), edit_resource_url
    render :action => :edit and return }
 end

And when everything is OK it redirects right, but there are any errors I don't get URL of edit action, I have show action URL, but edit form and errors are displayed. Is this all right or am I doing anything wrong? Here is my rendering of form for additional information:

<% link = "project_#{@comment.commentable_type.downcase}_comment_path"%>
<%= semantic_form_for [@project,@comment.commentable,@comment], :validate => true, :url => send(link,@project,@comment.commentable,@comment), do |f| %>
  <%= render 'form', :f => f %>
<% end %>
Was it helpful?

Solution

If there is no answers I think that this is all right, maybe render is render, but action is already done and URL changed. Anyway, thanks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top