select_tag からヘルパー メソッドを呼び出そうとしています。私はこれを試しました:
<%= select_tag(:themes, options_for_select({"Black" => "compiled/styles", "Green" => "compiled/styles2"})) %>
alert(this.options[this.selectedIndex].value)
メソッドを呼び出す代わりに配置すると、機能します。必要に応じてメソッドを呼び出すようにコードを変更するにはどうすればよいですか?
編集
私はこれを持っていますapplication.js
$(document).ready(function() {
$('#display_themes').change(function(){
$.ajax({url: '<%= url_for :controller => 'application', :action => 'set_themes()', :id => 'this.value' %>',
data: 'selected=' + this.value,
dataType: 'script'
})
})
});
そしてコントローラーにはset_themesメソッドがあります
def set_themes()
@themes = params[:id]
respond_to do |format|
redirect_to '/galleries'
format.html # index.html.erb
format.xml { render :xml => @themes }
end
end
問題は、ドロップダウンを変更しても@themesがまだ空です
Routes.rb
match '', :controller => 'application', :action => 'set_themes()'