2
我有这样的代码在我的职位/索引视图:呼叫控制器动作
-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是否安全?任何建议请。
我使用gem 'acts-as-taggable-on'
哈哈,这很容易,愚蠢的我。 TY – 2011-03-24 12:12:48