私は長い間グーグルで検索しましたが、私の問題に対する完全な答えは見つかりませんでした。
私のアプリでは、inherited_resourcesを使用しています。したがって、Commentオブジェクトを正常に作成した後、リダイレクトをオーバーライドしたいので、次のように記述します。
update! do |success, failure|
success.html { redirect_to parent_url }
end
1つの文字列で実行できることはわかっていますが、障害が発生したときにもアクションを追加する必要があるため、ブロックが必要です。だから私は書く:
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
そして、すべてがOKの場合、正しくリダイレクトされますが、編集アクションのURLが取得できないエラーがあり、アクションURLを表示していますが、編集フォームとエラーが表示されます。これは大丈夫ですか、それとも私は何か間違ったことをしていますか?追加情報のためのフォームのレンダリングは次のとおりです。
<% 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 %>