0

I would like to perform an ajax request by passing some data from the browser (some text values as a string) and render view of the same action to which I am sending request using ajax.

My workflow goes like this:

  1. User upload two files :calib and :inten.

  2. app saves the file using paperclip and parses the information in different instance variables.

  3. Once the file is parsed app delivers the message in the form of flash[:notice] in create action and immediately make pr list available to the user as a drop down list in the browser.
  4. There are two partials _form and _formTwo which gets rendered in create action.

  5. when I perform ajax request, I am in create view, and I am requesting other action named norm in the controller.

  6. After the ajax call I want app to render the norm.html.erb without refreshing the page.

My codes are here: http://pastie.org/private/keykmwbzcrv04dfvkufsew

I tried ajax using unobtrusive javascript but I dont know how to pass some data (mentioned above) using link_to or button_to helper.

With simple jquery ajax, I can pass data to the server but my page is not rendering. Development log shows that Page is rendered, but nothing changes in the browser page. I know I am missing something but unable to figure it out??

Development log output:

Started POST "/normalize" for 127.0.0.1 at 2014-04-30 13:38:43 +0200
Processing by UploadsController#normalize as */*
Parameters: {"data"=>"17,Poly-T-CY5,EukS_1209_25_dT"}
Upload Load (0.1ms)  SELECT `uploads`.* FROM `uploads` WHERE `uploads`.`id` = 17 LIMIT 1
Rendered uploads/_normalize.html.erb (0.2ms)
Rendered uploads/normalize.js.erb (1.0ms)
Completed 200 OK in 4ms (Views: 2.1ms | ActiveRecord: 0.1ms)

I hope I have explained my problem well, please let me know if I have not made myself clear??

JstRoRR
  • 3,693
  • 2
  • 19
  • 20

1 Answers1

0

Link_to allows you to pass it a data_hash as so:

<%=link_to("Link",link_path,:data=>{foo:"bar",hello:"goodbye"},remote:true)%>

Looking at your code, another problem is that the 'norm.html.erb' file is not a partial. In order to render it from 'norm.js.erb' you need to rename it '_norm.html.erb' so rails will recognize it as a partial.

kempchee
  • 470
  • 1
  • 4
  • 17
  • thanx for explaining...but I found a major hitch in my code and that's being dataType: 'string' in my ajax call which should be dataType: 'script'. I changed it and everything worked well. :) – JstRoRR Apr 30 '14 at 15:55