I have a form that makes a post request which works fine but it is changing the route in front-end to the API route.
In router
post "/blogs", BlogController, :create
In HTML form
<%= form_for @conn, Routes.blog_path(@conn, :create), [multipart: true], fn f -> %>
<label>
Title: <%= text_input f, :title %>
</label>
<label>
Type: <%= select f, :type, [
"Blog": "blog",
"Email": "email",
"Bot Builder": "Bot Builder",
"Appointments": "appointments"] %>
</label>
<label>
Sub Title: <%= text_input f, :sub_title %>
</label>
<label>
Author: <%= text_input f, :author %>
</label>
<label>
Image URL: <%= text_input f, :URL %>
</label>
<label>
File: <%= file_input f, :photo %>
</label>
<%= submit "Submit" %>
<% end %>
In Controller
def create(conn, blog_params) do
with {:ok, %Blog{} = blog} <- BlogCatalog.create_blog(blog_params) do
conn
|> put_status(:created)
|> render("show.json", blog: blog)
end
end
Before submitting the form URL: (http://localhost:4000/)
After submitting the URL in the frontend is http://localhost:4000/api/blogs
I want to stay on the same page on f.e
Thanks.