Is a javascript file that is included in one html.erb persistent even in the other view with a different url? For eg: Suppose the flow is if I click on Go button in new then the user is directed to show page and I include js file only in new.html.erb then is the js file also available in show?
new.html.erb
<%= javascript_include_tag 'common' %>
So are the functions in common.js file available in my_domain/show just like how it is available in my_domain/new? Or should I include the js file again in show.html.erb?
Also I would like to know the best way to include same javacript file in partials. For eg as below:
main.html.erb
<% if some_condition %>
<% render partial: 'first_partial' %>
<% elsif some_other_condition %>
<% render partial: 'second_partial' %>
<% else %>
<% render partial: 'first_partial' %>
<% render partial: 'second_partial' %>
<% end %>
_first_partial.html.erb
#some code
<%= javascript_include_tag 'common' %>
_second_partial.html.erb
#some code
<%= javascript_include_tag 'common' %>
Here in the main for if and elsif condition I render only one of the partials so I can include the js file in any partial but for the third else condition since both the partials are rendered, what is the best way to include the js file? and also I cannot include the js file in main because the js file is called after the html in the partials is rendered.
mainfile has other code also. I have only pasted the necessary content for this question. Theifconditions in the question are inside anotherifblock. So the js file is unnecessary when the other condition is not satisfied in main file. So I do not include it and also the js only has functions on the html elements in those partials.