Skip to content

christopherlai/phoenix-ujs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PhoenixUJS

One for one port of Rails UJS.

Install

yarn add https://github.com/christopherlai/phoenix-ujs.git

Add MIME types to config.exs

config :mime, :types, %{
  "text/javascript" => ["js"],
  "application/javascript" => ["js"],
  "application/ecmascript" => ["js"],
  "application/x-ecmascript" => ["js"]
}

Recompile mime.

$ mix deps.clean mime --build
$ mix deps.get

Usage

Add MIME type to router accepts plug.

plug(:accepts, ["html", "js"])

Set data-remote="true" on forms.

  <%= form_for @changeset, @action, [data: [remote: true]], fn f -> %>
    ...
  <% end %>

Handle the js format type in the controller.

def create(conn, params) do
  conn
  |> put_resp_content_type("application/javascript")
  |> render("create.js")
end

Create .js file

console.log("Hello!");

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published