Butter Beer
Butter Beer

Reputation: 1150

Jquery redirect with Ajax Calls to another page Rails

I am trying to implement two pages. The first page being a selection of the items I want to show on the second page.

On my first page, I have done a selection of the items which I want to render.

On click of a button, 1. the ids of these items will be placed in an array and 2. the user will be redirected to a new page through:

window.location.replace("/schedule");

Right now, I want to achieve the following:

Do an ajax call through rails to get each of the array items. i.e. make an ajax calls to the urls of myclass/[id]. The id belonging to the items in the array.

I am not sure how I could get my array items from the current page to the next page or if there is a better way of achieving this. Any advice or suggestion will be greatly appreciated.

Upvotes: 1

Views: 1121

Answers (1)

zachar
zachar

Reputation: 1095

Add :remote => true to your form. Then, app will render your action_name.js.erb view instead of action_name.html.erb. In js file you can put code, which will repleace div without redirection, f.e.

$('#div_id').html('<%= escape_javascript render(your_partial_name) %>');

You don't need to do anything special in partial and controller action, its all the same.

Upvotes: 2

Related Questions