jquery - render a partial form using the javascript variable in views rails -


this code selected drop down value...

var rolename = $("#server_role_ids").find(':selected').text(); 

this code calling partial form js writing statically name of form. in case "web"

$('#role_form').html('<%= escape_javascript(render :partial => "web") %>'); 

but want dynamically call partial form using rolename variable, below particular selected form:

$('#role_form').html('<%= escape_javascript(render :partial => "" + rolename) %>');  

if rolename "something" call "something" partial form.

i know stuff if (rolename == "web") else if (rolename == "relay"), that. want dynamically write without if else statements.

need guys.

the things tried ajax

i tried implementing ajax, don't know whether right way it. please let me know. new.html.erb javascript...

$.ajax({ url : "/servers/new", type : "post", data : {rolename : rolename , envid : environmentid}, datatype: "text" });  

so have sent variable controller

@rolename = params[:rolename]  

and want use this..

$('#role_form').html('<%= escape_javascript(render :partial => "#{@rolename}") %>');  

in views, new.html.erb.

is right way of doing ajax? can make work? or other idea or suggestion you??


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -