Comments (10)
@jodosha I can give it a try. Could you explain how the process looks from here ?
from hanami.
@pkurek Thanks for looking at this.
Action#redirect_to
will trust that the argument is a valid URL, and directly put the argument in the HTTP Location
header (see impl).
Now we can override this behavior in frameworks.rb
, and let the right Routes
object to capture that symbol argument, resolve it as an url, and pass back the control to the Action.
I haven't implemented it yet because there is one thing to solve: get the right Routes
object. Because Lotus has a multi application architecture, we had to namespace with the module of the application. So that MyApp::Application
(which inherits from Lotus::Application
) will have MyApp::Routes
.
Because that override is at the higher level Lotus::Action
, instead of MyApp::Action
, we can't easily implement like this, because it would only work for MyApp
.
def redirect_to(url, status: 302)
headers.merge!(LOCATION => MyApp::Routes.url(url))
self.status = status
end
This is a nice to have feature, but has some complications, so I would postpone after the first release.
from hanami.
This is a nice to have feature, but has some complications, so I would postpone after the first release
That's your call :)
Are there any things I could help with? Cause the other 3 opened issues labeled as help-wanted
miss requirements.
from hanami.
@pkurek they are all meant to be implemented for the next release.
from hanami.
I was playing with this and was wondering if, instead of simply mokeypatching redirect_to
in this gem (like Lotus::Action::Rack
is) it wouldn't be better to make Lotus::Action
itself provide an extension point, something like a route_resolver
object or even a method (not sure if better though) that would be given the symbol or string and decide how to handle it. Have any thoughts on this?
from hanami.
I was thinking about patching Lotus::Action
(propably Lotus::Action::Callable
) in lotusrb and passing <application_module>::Routes
into the action's instance, but your solution is much cleaner ;)
We could rely on #call
interface. This will allow passing object, method or even a proc
from hanami.
How can we dynamically get the routes (or the application) object from within the action? We would need it to be injected somehow, right?
from hanami.
@fuadsaud Now we have a constant that acts as a router wrapper. By convention, for a Bookshelf
application, we'll have a Bookshelf::Routes
, which is an instance of Lotus::Routes
.
We could implement this feature by injecting a custom module into Bookshelf::Action
, when the application is loaded, by using Lotus::Controller::Configuration#modules.
# lib/lotus/frameworks.rb
module Lotus::Frameworks::Action::NamedRedirect
private
def redirect_to(name)
# ...
end
end
from hanami.
@fuadsaud ping, any update?
from hanami.
This opens an inconsistency with routing helpers in views. Not a good idea.
from hanami.
Related Issues (20)
- Router - can i configure such that routing is matched with or without ending "/". HOT 1
- Can't use middleware in scope HOT 1
- Routes error when launching one specific slice, could be done automatically?
- rack app is being re-initialised for every request
- Trouble loading & using dry-monads with Hanami 2.1 beta HOT 5
- Track Hanami 2.2 progress here
- Not found route returns 500 instead of 404 HOT 1
- Implement static assets Rack middleware HOT 1
- Reintroduce Rake task for assets
- Handled errors should not log as errors
- Revisit config/puma.rb, and fix preloading issue
- Test with React and Tailwind HOT 3
- Use rack method override middleware by default
- Isolate assets in view parts to a `helpers` object
- Roll back all "short names" for asset helpers (image, video, favicon, js, javascript, css, stylesheet)
- Render new welcome view as the starter route HOT 1
- Fix use of helpers within parts HOT 7
- guard required? HOT 1
- Could not find gem 'hanami-router (~> 2.1.0.rc)' HOT 12
- 2.1 RC1 - bundler: command not found: hanami on Heroku deploy HOT 22
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 hanami.