Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors on redirect #99

Closed
erizocosmico opened this issue Apr 2, 2015 · 5 comments
Closed

Errors on redirect #99

erizocosmico opened this issue Apr 2, 2015 · 5 comments
Assignees
Labels
Milestone

Comments

@erizocosmico
Copy link

Hi,

I've been trying to get the errors of the previous action after a redirect (which I've seen it's possible according to lotus/controller code) but I can't. I've also been searching for examples on how to do this right but I found nothing.

I have this on my controller config:

cookies true
sessions :cookie, secret: "foo"

On my action after the redirect I have this:

def call(params)
  puts errors.inspect
end

The first time I submit my form everything is ok, I get the errors on the action after the redirect. But if I submit the form more times I get the same errors as the first time no matter what the input contents are.

I've also noticed that two cookies "rack.session" are set. One with the path "/" and one with the path "/foo" where /foo is the endpoint of the form action. Maybe it has something to do with that.

@jodosha
Copy link
Member

jodosha commented Apr 7, 2015

Hello @mvader Thanks for opening this ticket. Are you using this framework alone, or with lotusrb?

@erizocosmico
Copy link
Author

I'm using it with lotusrb.
On Apr 7, 2015 11:08 AM, Luca Guidi notifications@github.com wrote:Hello @mvader Thanks for opening this ticket. Are you using this framework alone, or with lotusrb?

—Reply to this email directly or view it on GitHub.

@jodosha
Copy link
Member

jodosha commented Apr 8, 2015

@mvader Which kind of error do you get? Is this related to hanami/hanami#196 ? Can you please post the stack trace here? Thank you.

@jodosha jodosha added the bug label Apr 8, 2015
@jodosha jodosha self-assigned this Apr 8, 2015
@jodosha jodosha added this to the v0.4.1 milestone Apr 8, 2015
@jodosha jodosha added the waiting label Apr 9, 2015
@erizocosmico
Copy link
Author

I don't get any error. It just doesn't work as expected. I've been able to reproduce even with the fix you mentioned in #196.

Just setup an application with cookies and the session like that:

cookies true
sessions :cookie, secret: ENV['WEB_SESSIONS_SECRET']

Once you've submitted a form with errors, on every other request the retrieved errors via the errors method are the same, no matter what the input parameters were.

As I said, two cookies are set, maybe that's the problem. I implemented the sessions and cookies myself using Rack::Session and it worked. With Rack::Session only one cookie was set.

New action:

module Web::Controllers::Foo
  class New
    include Web::Action

    def call(params)
      puts errors.inspect?
    end
  end
end

Create action:

module Web::Controllers::Foo
  class Create
    include Web::Action

    params do
      param :title, presence: true, size: 3..255
    end

    def call(params)
      if !params.valid?
          # foo
      else
         # foo
      end
    end
  end
end

@jodosha
Copy link
Member

jodosha commented Apr 18, 2015

Closing because I think it was fixed by #100

@jodosha jodosha closed this as completed Apr 18, 2015
@jodosha jodosha removed the waiting label Apr 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants