简体   繁体   中英

Variables in Javascript on Rails

For an Ajax function in Javascript in a Rails partial, such as the following:

$.ajax
({
    type: "GET",
    url: "<%= url_for :action => "offline", :controller=> "user", :id => user.id %>"
});

does the user in user.id have to be an instance variable?

If you call the partial using code like the following, user will be found automatically, so the properties will be found on it as well. If thats not the case then you will have to set user to be a instance variable in the controller.

<% @users.all do |user| %>
    <%= render user %>
<% end %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM