Git Product home page Git Product logo

Comments (7)

spohlenz avatar spohlenz commented on May 18, 2024

Hi @slenderock. Sorry for the delay in looking into this. I have now implemented both of these features in master.

To change the redirect path, you can use the return_to method within a resource definition. It accepts an optional :on option to specify the action, along with a block which is evaluated within the context of the admin class. e.g.

Trestle.resource(:articles) do
  # Update return location for a single action
  return_to on: :create do |instance|
    path(:edit, id: to_param(instance))
  end

  # Update return locations for create, update and destroy
  return_to do
    path(:index)
  end
end

I have also implemented the remove_action method to properly remove unwanted resource actions. Relevant buttons (e.g. save, delete, etc) will also be removed when removing an action.

Trestle.resource(:articles) do
  remove_action :edit, :update
end

from trestle.

hdbreaker avatar hdbreaker commented on May 18, 2024

Hi I'm not been able to reproduce the redirect behaviour:

The overwriting function is triggered:

return_to do
    path(:index)
end

But path() function is undefined.

from trestle.

maikokuppe avatar maikokuppe commented on May 18, 2024

Hi I'm not been able to reproduce the redirect behaviour:

The overwriting function is triggered:

return_to do
    path(:index)
end

But path() function is undefined.

Same for me.

It worked for me like this:

return_to on: :destroy do |instance|
  edit_orders_admin_path(id: instance.order_id)
end

This returns to the edit view of the Order which the instance belongs to. There are also methods for other relations and methods. Just run methods in the debugger in that block.

from trestle.

spohlenz avatar spohlenz commented on May 18, 2024

The return_to blocks are now evaluated within the context of the controller rather than the admin.

Here is an up-to-date version of my previous example:

Trestle.resource(:articles) do
  # Update return location for a single action
  return_to on: :create do |instance|
    admin.instance_path(instance, action: :edit)
  end

  # Update return locations for create, update and destroy
  return_to do
    admin.path(:index)
  end
end

from trestle.

LimeBlast avatar LimeBlast commented on May 18, 2024

I'm trying to use this to redirect after a delete, but I'm running into some trouble.

For context, we're displaying a list of Block records within the Page (block belongs_to page) admin interface, and are using the standard actions method to display the delete button for each of these.

Once a Block has been deleted, we want to redirect it back to the Page admin, so I've added the following to the block_admin.rb file:

  return_to on: :destroy do |instance|
    admin.instance_path(instance.page, action: :edit)
  end

But it isn't working, resulting in the error Couldn't find Cms::Block with 'id'=72 because it's redirected to /trestle/blocks/72/edit (rather than /trestle/pages/72/edit)

I'm sure this is just a case of passing the correct parameter to the instance_path method to have it redirect to the pages admin, but I can't work out what this should be.

Thank you.

from trestle.

spohlenz avatar spohlenz commented on May 18, 2024

@LimeBlast Since you are within the blocks admin, the admin in your snippet refers to the BlockAdmin class (and its routes), rather than the desired PageAdmin. Try replacing admin with PageAdmin to reference it directly.

from trestle.

LimeBlast avatar LimeBlast commented on May 18, 2024

Thank you, @spohlenz - I think you meant PagesAdmin, rather than PageAdmin, but I've updated it to the following, which seems to work:

  return_to on: :destroy do |instance|
    PagesAdmin.instance_path(instance.page, action: :edit)
  end

UPDATE: or maybe you did mean PageAdmin, and I've named it wrong in my codebase - either way, the above works, Thank you :)

from trestle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.