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

elixir no route found for GET /torch #93

Closed
MattGaud2425 opened this issue Aug 13, 2018 · 16 comments
Closed

elixir no route found for GET /torch #93

MattGaud2425 opened this issue Aug 13, 2018 · 16 comments

Comments

@MattGaud2425
Copy link

After torch install I get no route found when pointing the browser /torch.

@zberkom
Copy link
Contributor

zberkom commented Aug 13, 2018

Hey @mattgaudio 👋 Thx for giving torch a try! Yep, torch doesn't expose anything at /torch. You'll need to follow the steps in the readme to actually run the torch generators. After you do that, you will end up with the admin interface for whatever schema & controller that you generate.

@MattGaud2425
Copy link
Author

I get this error after running the torch.gen.html generator. when trying to navigate to the index.

function Routes.static_path/2 is undefined (module Routes is not available)

@zberkom
Copy link
Contributor

zberkom commented Aug 14, 2018

@mattgaudio Ah, your app must not have been generated with phoenix 1.3. In your appname_web.ex the :view function is importing your routes instead of aliasing them like phoenix 1.3 does i.e (1alias ExampleWeb.Router.Helpers, as: Routes). Feel free to just remove the Routes.from the front ofstatic_path`, since you are already importing all your routes.

@MattGaud2425
Copy link
Author

I generated using phx 1.3

def view do
quote do
use Phoenix.View, root: "lib/mythic_web/templates",
namespace: MythicWeb

  # Import convenience functions from controllers
  import Phoenix.Controller, only: [get_flash: 2, view_module: 1]

  # Use all HTML functionality (forms, tags, etc)
  use Phoenix.HTML

  import MythicWeb.Router.Helpers
  import MythicWeb.ErrorHelpers
  import MythicWeb.Gettext
end

end

@zberkom
Copy link
Contributor

zberkom commented Sep 4, 2018

@mattgaudio Have you updated your endpoint.ex to include the following per the second step in the readme install instructions?

plug(
  Plug.Static,
  at: "/torch",
  from: {:torch, "priv/static"},
  gzip: true,
  cache_control_for_etags: "public, max-age=86400"
)

@cdesch
Copy link

cdesch commented May 20, 2019

I ran into the same issue. Not sure if this is a Phoenix 1.4.6 issue

@cpjolicoeur cpjolicoeur modified the milestone: v3.0.0 Sep 13, 2019
@dfang
Copy link

dfang commented Mar 19, 2021

Phoenix v1.5.8
Torch 3.6

i got this

  plug Plug.Static,
    from: {:torch, "priv/static"},
    gzip: true,
    cache_control_for_etags: "public, max-age=86400",
    headers: [{"access-control-allow-origin", "*"}]

before

# Serve at "/" the static files from "priv/static" directory.
  #
  # You should set gzip to true if you are running phx.digest
  # when deploying your static files in production.
  plug Plug.Static,
    at: "/",
    from: :dummy,
    gzip: false,
    only: ~w(css fonts images js favicon.ico robots.txt)

and

  scope "/admin", DummyWeb.Admin, as: :admin do
    pipe_through :browser

    resources "/posts", PostController
  end 

in router.ex

but i still can't load /torch/torch.js and /torch/theme.css

截屏2021-03-19 下午10 26 42

@cpjolicoeur
Copy link
Member

@dfang Please refer to the README installation/setup instructions. Your Plug.Static plug for the Torch assets doesn't have the at: "/torch" key telling the plug where to mount that static plug.

@dfang
Copy link

dfang commented Mar 19, 2021

hi, i got another error when i started from scratch

$ elixir -v
Erlang/OTP 23 [erts-11.1.7] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]
Elixir 1.11.3 (compiled with Erlang/OTP 23)

$ phoenix version: 1.5.8
  mix phx.new dummy
  cd dummy 
  mix deps.get
  add  {:torch, "~> 3.6"} to mix.exs
  mix deps.get
  npm i --prefix assets


  # add this to endpoint.ex before the line plug Plug.Static, at: "/",
  plug Plug.Static,
    at: "/torch",
    from: {:torch, "priv/static"},
    gzip: true,
    cache_control_for_etags: "public, max-age=86400",
    headers: [{"access-control-allow-origin", "*"}]
  
  # add this to config.exs
  config :torch,
    otp_app: :dummy,
    template_format: "eex"


  mix torch.install

  mix ecto.create
  
  mix torch.gen.html Blog Post posts title:string body:text published_at:datetime published:boolean views:integer
  
  mix ecto.migrate

  mix torch.gen.html Blog Post posts --no-schema --no-context --web Admin title:string body:text published_at:datetime published:boolean views:integer


  # add this to router
  scope "/admin", DummyWeb.Admin, as: :admin do
    pipe_through :browser

    resources "/posts", PostController
  end

  mix phx.server

  open http://localhost:4000/admin/posts

截屏2021-03-20 上午2 11 48

both app.eex and torch.eex in layout rendered

does torch support phoenix v1.5.8 ?

@cpjolicoeur
Copy link
Member

It could be that Phoenix has again switched how they handled layouts. In v1.5 they changed somethings that were undocumented, and perhaps they have changed them again in a patch release.

You can see the discussions in #168, #169, and #172 where this was modified for 1.5 (at the time 1.5.1). Perhaps Phoenix has changed internals again. I'll have to look into it.

From a quick test locally, in spinning up a new app on Phoenix 1.5.8 it does appear that is the case. You can go into your generated torch controller and change the plug(:put_root_layout, {..., "torch.html"}) line to just use plug(:put_layout.... instead and I think that will solve your problem for now.

@cpjolicoeur
Copy link
Member

@dfang It appears that maybe this issue is dependent on whether or not the Phoenix 1.5 application was generated with the --live flag or not.

When the application is not using LiveView, the torch controllers can/should just use the put_layout method, and when used with LiveView, the torch controllers can/should use the put_root_layout method.

We will have to made some updates to the codebase so that the Torch generators are a bit more sophisticated for each case.

@cpjolicoeur
Copy link
Member

@dfang please pull down the newly released version 3.6.1 and let me know if you are still having the same problems.

@dfang
Copy link

dfang commented Mar 20, 2021

thanks, it works when just replace put_root_layout with put_layout in admin/post_controller.ex

@waldofe
Copy link

waldofe commented May 18, 2022

Erlang/OTP 24 [erts-12.3.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]

Elixir 1.13.4 (compiled with Erlang/OTP 24)

* torch 4.1.0 (Hex package) (mix)
  locked at 4.1.0 (torch) d0d09eb0

Followed the suggestions here. It still doesn't seem to be able to find the style files.

@cpjolicoeur
Copy link
Member

@osluf can you provide any more details? Your config and endpoint listings maybe? The current versions of Torch both work on a baseline Phoenix project, so we'd need some more info about your current setup, or a sample repository with a minimal failing example to take a look.

@tyurtyubek
Copy link

Erlang/OTP 24 [erts-12.3.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]

Elixir 1.13.4 (compiled with Erlang/OTP 24)

* torch 4.1.0 (Hex package) (mix)
  locked at 4.1.0 (torch) d0d09eb0

Followed the suggestions here. It still doesn't seem to be able to find the style files.

Did you manage to fix this problem?

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

7 participants