PatrykosA
Hello,
I have a page with a button “Save” (#room-socket-save-changes) and a select (#room-socket-select) which contains id.
There’s a content of some files below.
router.ex
pipeline :api do
plug :accepts, ["json"]
end
scope "/api", MdbmsWeb, as: :api do
pipe_through :api
scope "/v1", Api.V1, as: :v1 do
resources "/room_sockets", Room_socketController, only: [:index, :show, :update]
end
end
room_socket
schema "room_sockets" do
field :name, :string
belongs_to :room, Mdbms.Room, foreign_key: :room_id
has_one :connection, Mdbms.Connection
timestamps()
end
room_socket_controller.ex
def update(conn, %{"id" => id, "name" => name, "room_id" => room_id}) do
room_socket_params = %{"name" => name, "room_id" => room_id}
room_socket = Repo.get!(Room_socket, id)
changeset = Room_socket.changeset(room_socket, room_socket_params)
case Repo.update(changeset) do
{:ok, post} ->
conn
|> put_flash(:info, "Post updated successfully.")
{:error, changeset} ->
# render(conn, "edit.html", post: post, changeset: changeset)
end
end
app.js
$('#room-socket-save-changes').on('click', function() {
var room_socket_id = $('#room-socket-select').val();
var name = $('#input-rs-name').val();
var room_id = $('#select-rs-locations').val()
$.ajax({
type: 'PUT',
url: '/api/v1/room_sockets/' + room_socket_id,
data: {
name: name,
room_id: room_id
},
dataType: "json",
success: function() {
alert("success!");
},
error: function() {
alert('error!');
}
});
});
When I click button “Save” I get alert “error!” and an error shows in my terminal:
[error] #PID<0.463.0> running MdbmsWeb.Endpoint (cowboy_protocol) terminated
Server: localhost:4000 (http)
Request: PUT /api/v1/room_sockets/1
** (exit) an exception was raised:
** (ArgumentError) flash not fetched, call fetch_flash/2
(phoenix) lib/phoenix/controller.ex:1236: Phoenix.Controller.get_flash/1
(phoenix) lib/phoenix/controller.ex:1218: Phoenix.Controller.put_flash/3
(mdbms) lib/mdbms_web/controllers/api/v1/room_socket_controller.ex:1: MdbmsWeb.Api.V1.Room_socketController.action/2
(mdbms) lib/mdbms_web/controllers/api/v1/room_socket_controller.ex:1: MdbmsWeb.Api.V1.Room_socketController.phoenix_controller_pipeline/2
(mdbms) lib/mdbms_web/endpoint.ex:1: MdbmsWeb.Endpoint.instrument/4
(phoenix) lib/phoenix/router.ex:278: Phoenix.Router.__call__/1
(mdbms) lib/mdbms_web/endpoint.ex:1: MdbmsWeb.Endpoint.plug_builder_call/2
(mdbms) lib/plug/debugger.ex:122: MdbmsWeb.Endpoint."call (overridable 3)"/2
(mdbms) lib/mdbms_web/endpoint.ex:1: MdbmsWeb.Endpoint.call/2
(plug) lib/plug/adapters/cowboy/handler.ex:16: Plug.Adapters.Cowboy.Handler.upgrade/4
(cowboy) /osA/Elixir/mdbms/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
I’ve tried some solutions but the error still shows up. Do you have any idea where I make a mistake?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used?
I’ve got two Github accoun...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #elixirconf-us
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sanswork
Try replacing
in your controller
with
PatrykosA
Thank you. It helped. The error disappeared and both fields are updated:
Unfortunately I still get an alert “error!” from my jQuery.ajax.
sanswork
Check out the network tab in your developer console to see whats happening with the request. It might just be that you need to change the text reply type to a json one as shown below. It’s probably on the jquery side though at that point.
text conn, “OK”
json conn, %{}
PatrykosA
You’re right. I’ve changed that and it works fine now. Thanks again!