简体   繁体   中英

Can you pass variables from a view to controller?

I have comments that are tied to a specific ID. After 10 seconds, I want a partial to refresh to display comments related to that time interval. This means I would have to make some sort of call, as seen in my controller method:

def update_comments


    @video = Video.find(params[:id])
    @comments = Comment.where(:video_id=> @video.id).order("time_stamp ASC")
    @change = Change.find_by(:user_id => current_user.id, :video_id=> @video.id)


    # puts "onupdate comments"
    respond_to do |format|
        format.js
    end
end

However, I don't know how to pass the argument :id from the view to the controller (doing :locals => {...} doesn't work)

使用ajax请求来调用服务器端,您可以在其中传递任何参数

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