Comments (7)
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.
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.
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.
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.
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.
@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.
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)
- uninitialized constant custom field rails 7 HOT 3
- Changing date format HOT 3
- Option to disable form as "show" view? HOT 1
- My custom helper not is recognized HOT 2
- How i use concerns at trestle? HOT 1
- Remove Multiple Records From MODEL Page
- WebSockets / action_cable support? HOT 2
- Pagination for a custom index View
- Fix typo for Vietnamese locale HOT 1
- Direct upload or chunked file upload support? HOT 2
- Fails without sassc-rails
- Unable to locate favicon.ico in public folder HOT 1
- Best Way To Provide a Select Dropdown for belongs_to that is optional HOT 2
- Filter with a select list
- Enum Radio Button Missing Current Selection HOT 11
- Errors on check_box fields not displaying HOT 2
- Customize navbar HOT 3
- Mongoid support HOT 2
- Use importmap in Trestle HOT 6
- Fix Brazilian Portuguese translation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from trestle.