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

Allow respond_with methods to accept a block #1053

Closed
westonganger opened this issue Jan 30, 2019 · 4 comments

Comments

Projects
None yet
4 participants
@westonganger
Copy link
Contributor

commented Jan 30, 2019

Currently the respond_with format methods only allow a String or Proc. The Proc syntax is awkward and unexpected. It is also currently undocumented.

respond_with do
  html -> {
    flash[:notice] = "Sucesss"
    render("my_action.slang")
  }
end

It would be alot nicer if we could do simply pass a Block like the following:

respond_with do
  html do
    flash[:notice] = "Sucesss"
    render("my_action.slang")
  end
end

I tried creating a patch:

module Amber::Controller::Helpers::Responders
  def html(&block)
    @available_responses[TYPE[:html]] = block.call; self
  end
end

However I kept running into the following error:

undefined local variable or method 'html'

      html do
      ^~~~
@elorest

This comment has been minimized.

Copy link
Member

commented Jan 31, 2019

I'll look into this.

@elorest

This comment has been minimized.

Copy link
Member

commented Jan 31, 2019

I've submitted a PR to address this.

@robacarp

This comment has been minimized.

Copy link
Member

commented Feb 7, 2019

@Sija

This comment has been minimized.

Copy link
Member

commented Feb 9, 2019

@robacarp yep, fixed by #1054.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.