jquery - Rails: Keep controller after AJAX call -
i have question data in controller after ajax call view.
i have dropdown uses remote: true able work ajax
<%= t('label') %> <%= collection_select("items", :id , @items, :id, :selector_title, { :prompt => false, :selected => @selected_id }, {:data => {:remote => true, :url => "/controller/do_something", :method => "post"}}) %> in routes file specified route
match '/path_to_controller_method', to: 'controller#do_something', via: 'post' this works fine. do_something method gets executed in controller. not understand is, why variables like:
@wrapper nil initialized in index method? have reinitialize variables again, after ajax call view?
an ajax call independent call has assigned controller, , assigned method within controller. works pretty normal request, except doesn't reload whole page.
now, variable: @wrapper - if has been initialized in index method, needs initialized in assigned method: do_something too, or before_action, initialize method there, , call before_action before index & do_something.
all in all, ajax call works pretty other request, , need initialise instance variables unless using before_action.
Comments
Post a Comment