Rails: Keeping a partial DRY when using locals -
i have partial being reused couple controllers.
right have partial set accept 2 objects don't want do.
-if @article .main-inner .article-header .article-title =@article.title -if !@article.byline.blank? %span#byline =@article.byline %span#timestamp =@article.publish_date.strftime("%a, %b %d, %y %i:%m %z") .article-content =truncate(@article.content, :length => 600).html_safe -else .main-inner .article-header .article-title =article.title -if !article.byline.blank? %span#byline =article.byline %span#timestamp =article.publish_date.strftime("%a, %b %d, %y %i:%m %z") .article-content =truncate(article.content, :length => 600).html_safe
when @article
def show @article = article.find_by_permalink(params[:permalink]) end
when through locals
$("#article").html("<%= escape_javascript render(:partial => 'article/view', :locals => { :article => @newarticle }) %>")
1) how can consolidate partial not use if @article.
2) in js. proper syntax rendering partials don't have :partial => 'article/view' , use :locals?
if partial should use article(local) instead of @article(not instant variable), , should pass in locals when render partial.
render(:partial => 'article/view', :locals => { :article => @article })
or
render(:partial => 'article/view', :locals => { :article => @newarticle })
Comments
Post a Comment