0

In my controller I am using render update,but I want to update only if div element if present. In order to check if div element is present, I am using page.select but its not responding with anything,neither error or output,here is my code

def post_update
render :update do |page|
   page.replace_html('div_id':partial=>'my_partial') unless page.select("#div_id").blank?
  end
end

is there anything I am missing here ?

Lohith MV
  • 3,798
  • 11
  • 31
  • 44

1 Answers1

1

You can't use ruby conditionals like that in rjs: that "unless" and page.select are executed on your server and have no idea what the contents of the DOM are.

I once wrote a blog post with a few ways of dealing with this. The short version is probably "generate Javascript fragments with your conditions". These days I'd stay away from rjs: render json or HTML and have some JavaScript on your page that knows what to do with it.

Frederick Cheung
  • 83,189
  • 8
  • 152
  • 174