piotrmurach / loaf

Manages and displays breadcrumb trails in Rails app - lean & mean.
MIT License
407 stars 24 forks source link

Active not being set properly #38

Closed ericraio closed 5 years ago

ericraio commented 5 years ago

I have a very simple action here and when a product is invalid and I render the new action, the url does not match properly

# POST /admin/products
def create
  product.assign_attributes(product_params.merge(account: current_account).permit!)

  if product.save
    flash[:success] = I18n.t("flash.message.create.success", resource: I18n.t("resource.product"))
    redirect_to admin_products_path
  else
    breadcrumb I18n.t("buttons.actions.new", resource: I18n.t("resource.product")), new_admin_product_path
    render :new
  end
end
piotrmurach commented 5 years ago

Hi Eric,

Thanks for giving loaf a try.

Having looked at your example, one thing that I'm rather confused about is that you expect to have a breadcrumb on create action that gets triggered by POST request? I mean, there is no page that corresponds with create action. I would try actually defining breadcrumb in the new action itself.

ericraio commented 5 years ago

Hi Eric,

Thanks for giving loaf a try.

Having looked at your example, one thing that I'm rather confused about is that you expect to have a breadcrumb on create action that gets triggered by POST request? I mean, there is no page that corresponds with create action. I would try actually defining breadcrumb in the new action itself.

Hey @piotrmurach Thank you for responding.

My issue is that if the parameters are invalid on the Create action, I then render the new action instead of redirect. Just like standard rails scaffold

By rendering the new action during the create action as you can see with the example above, the Breadcrumb is never set which is why I call breadcrumb.

Any suggestions on how to fix this?

piotrmurach commented 5 years ago

Eric, your issue as reported is not very clear to me. The 'properly' is rather vague word and doesn't specify what you expect to happen vs what actually happens. The code sample doesn't answer these questions. Ideally, if you could either create an example of a Rails app that replicates the issue or even better submit a failing test. The integration tests use a dummy Rails app to confirm behaviour. You could, for example, add new products controller that demonstrates the problem. Here is an example of posts controller that handles the create action.