开发者

rails3 + Jquery data dispay issue

开发者 https://www.devze.com 2023-02-19 17:16 出处:网络
I have a Rails3 application with JQuery. and I have the following code (I have a div with id \'new\' as well)

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号