rails3 + Jquery data dispay issue
I have a Rails3 application with JQuery. and I have the following code (I have a div with id 'new' as well)
$.ajax({
type: "GET",
url: '/users/new',
success: function(data) {
$("#new").html( data );
}
});
and in my users controller new action is as follows
def new
@user = User.new
@sample_value = "sample value"
end
But when i try to display the variable @sample_value
in the view it seems like its blank (doesnt have any value)
How can i pass an instance variable (@) from my controller to views
please help
my setup is as follows
Rails 3 JQuery (CDN)
ht开发者_如何学Pythontp://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js
Linux
thanks in advance
cheers
sameera
Simplest way to go is just render your data
def new
@user = User.new
@sample_value = "sample value"
render :text => @sample_value
end
But good practice is to hadle it as a js
request and make a responde in your new.js.erb
file
精彩评论