Ce ne pas possible, mon ami.
As mentioned in the comments, Ruby is server; javascript is client. This means one of two things:
- build the javascript at runtime (not recommended)
- send the ajax / javascript value to the server (via Ajax)
To get this working properly, you'll need to send the request through ajax:
#app/assets/javascripts/application.js
$(document).on("change", "#some_id", function(e) {
$.get("forms/update", {index: $(this).val(), value: $(this).attr('id').to_i});
});
This would need to be addressed by the appropriate route & controller action:
#config/routes.rb
get "color_form", to: "application#color_form"
#app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
respond_to :js, :html
def color_form
@id = params[:id]
@value = params[:value]
end
end
#app/views/application/color_form.js.erb
$('option_value_0').html('<%=j render partial: 'color_form', locals: { index: @index, id: @value } %>')
--
Yes, it's long-winded, but it's the right way.
If you wanted to shortcut, you'd be able to preload the color_form partial, and then use the javascript functionality to change the id or value params. I can write about this if you want.
Preload
If you wanted to do this without ajax, the standard way (this includes modals, too) is to append the partial to your page and "hide" it.
This way, your JS has the actual HTML code to either show, or append to other parts of the page:
#view
<div class="hidden">
<%= render partial: 'color_form', locals: { f: f, index: "x", id: "y" } %>
</div>
#app/assets/javascripts/application.js
$(document).on("change", "#some_id", function(e) {
$partial = $(".hidden").html();
$partial.find("#id").html($(this).attr('id').to_i);
$partial.find("#index").html($(this).val());
$('option_value_0').html($partial);
});