Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

Mysterious Ruby Block behavior: &block vs. {block.call} -


when writing helper printing javascript can used both other helpers , views, stumbled upon following problem:

def javascript(print_tag = false, &block)   content_for(:javascript)     if print_tag       javascript_tag(&block)          # not work       javascript_tag { block.call }   # work      else       capture(&block)     end   end end 

this helper should called javascript { "alert('hurray'); }.

in first alternative - expected work - rails javascript_tag helper renders empty <script type="text/javascript"> //<![cdata[ //]]> </script> tag.

the second alternative, however, works expected.

what's going on there? how can different?

you doing on views, right?

<%= javascript { "alert('hurray');" } %> 

but content_tag(&block) work, should call javascript way content_tag intended used in views, is:

<% javascript %>   alert('hurray'); <% end %> 

content_tag's behavior different depending on it's called from, see function block_called_from_erb? in source code. in first case function returns true because block come erb (and it's concated, don't want that!), in second returns false (you re-created block scratch) , content_tag returns string content, want.

# ./action_view/helpers/javascript_helper.rb tag = content_tag(:script, javascript_cdata_section(content), html_options.merge(:type => mime::js)) if block_called_from_erb?(block)   concat(tag) else   tag end 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -