Code Monkey home page Code Monkey logo

Comments (10)

pkurek avatar pkurek commented on May 18, 2024

@jodosha I can give it a try. Could you explain how the process looks from here ?

from hanami.

jodosha avatar jodosha commented on May 18, 2024

@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.

pkurek avatar pkurek commented on May 18, 2024

@jodosha

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.

jodosha avatar jodosha commented on May 18, 2024

@pkurek they are all meant to be implemented for the next release.

from hanami.

fuadsaud avatar fuadsaud commented on May 18, 2024

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.

zlw avatar zlw commented on May 18, 2024

@fuadsaud 👍

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.

fuadsaud avatar fuadsaud commented on May 18, 2024

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.

jodosha avatar jodosha commented on May 18, 2024

@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.

runlevel5 avatar runlevel5 commented on May 18, 2024

@fuadsaud ping, any update?

from hanami.

jodosha avatar jodosha commented on May 18, 2024

This opens an inconsistency with routing helpers in views. Not a good idea.

from hanami.

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.