silverdr

silverdr

Serving different content formats from single controller's action

Looking for a way to distinguish whether e. g. document.html or document.pdf was requested and to serve appropriate content format in return. Something akin to respond_to in that other framework. I think I solved it already before but I can’t recall now. Hints/pointers appreciated.

First Post!

Most Liked

LostKobrakai

LostKobrakai

The need for multiple modules comes from the fact that function components normalized to arity-1 functions (NameSpaceFormat.name(assigns)), which receive only assigns. There’s no additional parameter anymore, which would pass the format to the function transforming assigns to the format being rendered. Switching by format now happens on the view/layout/root layout level with put_view/put_layout/put_root_layout and them being updated to accept keyword lists.

Phoenix.View had render("name.format", assigns), which could switch on format within the same module. If you want to retain that you can keep using Phoenix.View by manually depending on it.

In regards to “viewless phx” I’m not sure what you’re refering to. Yes Phoenix.View is no longer used, but you can and likely will have modules serving the purpose of views still. Personally I’m a fan of phoenix having changed to dumping those modules next to controllers though, as it makes that fact less discoverable. I guess the tldr there would be: On a high level nothing changed (views are still a thing), but the implementation changed.

Last Post!

silverdr

silverdr

Ah, that would explain. So this in fact changed, which might be the reason why in the recent docs I couldn’t find how I think I did it previously. TNX

Where Next?

Popular in Questions Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement