I’m trying to create a modal window window containing detailed information.
# show.html.erb
<%= link_to 'Info', player_info_path, :remote => true %>
# Controller
def player_info
@player = Player.find(1) # ignore the hard-coding
end
# player_info.js.erb
alert(<%= @player.name %> ); # alerts 'undefined'
$("#player_info").html("<%= escape_javascript(render("detailed_info"))%>");
The javascript is executed but how can i get the detailed info from the controller to the javascript or can I perform a CRUD-action from the js.erb?
As noted in the comment, you were missing the quotes in
alert("<%= @player.name %>");.You have everything else set up correctly – so you can access @player attributes in your player_info.js.erb like so:
@player.attribute.