2
votes

I am finding few ways to get my work routine good with Phoenix as I have with rails, There are some perspectives which I am looking in Phoenix are.

1: In rails, I have my controller and my view, also the CSS and JS files alongside, When I want to include CSS files only in one relevant view, I only do as

<%= yield :head %>

and In my View file, I only do

<% content_for :head do %>
  <%= stylesheet_link_tag "views/index/landing.css" %>
<% end %>

That's it. My CSS file is only loading for my relevant view.

2: For JS, I have application.js file in which I included my other libs and in the end, I have admin.js in which I have included my every other file as

//= require jquery
//= require dataTables/jquery.dataTables
//= require jquery_ujs
//= require bootstrap.min
//= require admin/admin.js

admin.js.coffee file

#= require admin/sign_up.js.coffee
#= require admin/company.js.coffee
#= require admin/user.js.coffee

3: For every JS file What I am doing is, e.g for Signup view's JS file I have done as under, in the very end of the file,

window.initializeSignUp = ->
  onSignUp()

after this What I only need in my sign up view is

<script>
  $(document).ready(function () {
    window.initializeSignUp();
  });
</script>

Now it's only calling that method of Signup and everything is working fine. On the other hand, I love Elixir it's a very good and lovable language to work in, BUT whenever I start project in it, I already got afraid of Brunch and how Assets are going to be handled.

for those who will read the question and will just downvote without even understanding the main issue here: Am a newbie to Phoenix for creating an APP with views and assets, etc.

I just need a clear and correct answer to work with Phoenix without using brunch or any web-pack solution, But a normal way, Is that possible in possible?

1
What Rails does for (2) is not "normal". Rails has its own brunch/webpack-like thing which does this concatenation. Phoenix does not include any such functionality.Dogbert
I am only finding a reliable way to solve the problem for a person who don't know Brunch or web pack.Junaid Farooq

1 Answers

1
votes

I believe your question has been answered here. The answer shows how to add page specific javascript but the same technique can be done for your css styles.

Here's a good explanation of how templates/views work in Phoenix.