我的帖子/索引视图中有这个代码: -tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class| = link_to tag.name, { :action = :tag, :id = tag.name }, :class = css_class 这是我的控制器: def index @posts = Post.page(p
-tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class| = link_to tag.name, { :action => :tag, :id => tag.name }, :class => css_class
这是我的控制器:
def index @posts = Post.page(params[:page]).per(5) tag_cloud respond_to do |format| format.html # index.html.erb format.xml { render :xml => @posts } end end def tag @posts = Post.tagged_with(params[:id]).page(params[:page]).per(5) @tags = Post.tag_counts_on(:tags) render :template => 'posts/index' end def tag_cloud @tags ||= Post.tag_counts_on(:tags) end
我想将标签云从索引视图移动到应用程序布局,但我不知道如何从那里调用控制器操作方法.
另外,我有疑问,这个MVC安全吗?请给我任何建议.
我正在使用宝石’act-as-taggable-on’
移动tag_cloude的代码def tag_cloud @tags ||= Post.tag_counts_on(:tags) end
到ApplicationHelper然后你可以使用它<%= tag_cloud%>在您的应用程序布局中.