如何从Ruby on Rails应用程序布局中调用特定控制器的操作?
- 内容介绍
- 文章标签
- 相关推荐
本文共计268个文字,预计阅读时间需要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(p)end
我的帖子/索引视图中有这个代码:-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%>在您的应用程序布局中.
本文共计268个文字,预计阅读时间需要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(p)end
我的帖子/索引视图中有这个代码:-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%>在您的应用程序布局中.

