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

Using with Phoenix Framework #7

Closed
adamwiggall opened this issue Sep 2, 2015 · 4 comments
Closed

Using with Phoenix Framework #7

adamwiggall opened this issue Sep 2, 2015 · 4 comments

Comments

@adamwiggall
Copy link

Daniel,

This looks like a great package. As an Elixir/Phoenix newcomer how might I use it with the Phoenix Framework?

I have it installed as a dependency but I'm unsure where to put the render method and how it sits with views and templates.

Thanks in advance

@danielberkompas
Copy link
Owner

Hi Adam,

Where you put the render function is up to you, but I suggest that you create a module in lib/my_app/ and put the render function in there.

To actually use the render function, add this function to your web.ex file in the "controller" section:

def xml(conn, value) do
  conn = %{conn | resp_headers: [{"content-type", "application/xml"}]
  send_resp conn, 200, value
end

This will add this xml rendering function to all your controllers. You can then use it like so:

def index(conn, _params) do
  xml conn, MyApp.MyModule.render
end

If you're going to be rendering a lot of TwiML, I recommend that you also check out my Telephonist repo. It can help you organize all the rendering into an elegant state machine.

@adamwiggall
Copy link
Author

Daniel,

Thanks for the thorough response. I do indeed have a lot of TwiML, currently about 300 lines residing in a Sinatra app that's begging to be rewritten. I came across Telephonist after I posted this question, it looks perfect for my needs.

Without wishing to pollute this repo's issues, I don't suppose there is a more detailed blog post planned for setting up Telephonist with Phoenix is there? :)

@danielberkompas
Copy link
Owner

@adamwiggall I don't have a blog post on using Telephonist with Phoenix yet, no. It'll be a couple weeks before I can come out with one, but I'll add it to my list. I've tried to make the telephonist docs pretty comprehensive, so hopefully that helps.

@adamwiggall
Copy link
Author

Thanks Daniel, I look forward to the post, and I'll work through the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants