0

I have a rails 4 app where I have some Javascript that generates a .jst.ejs template that looks like:

<!--name.jst.ejs which is in assets/javascripts/templates-->
<input type="text" name="store[name]" placeholder="Store Name" />

then I have a rails partial ( called _name.html.erb in my views directory) that looks like:

<input type='text' name="store[name]" value="<%= @store.name%>" />

What I'm trying to do is to keep this DRY, and only have to use the one ejs file (instead of having basically a duplicated .ejs and .erb file).

Is there a way to:

  1. Call an ejs file as a rails partial: eg something like: <%= render "name" %> (which renders the name.jst.ejs file?
  2. Also, because the two files are somewhat different, is there a way to differentiate the code if it was rendered as ejs vs erb? For example, something like:

<input type='text' name="store[name]" <% if erb %> value="<%= @store.name %>" <% else %> placeholder="Store Name" <% end %> />

1 Answer 1

1
  1. Try something like:

    <%= render "name.jst.ejs", :formats => [:erb], isErb: true %>

  2. Then in the partial, check if isErb is present
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.