Ruby-on-rails – Call the controller from the application layout

I have this code in my posts/index view:

-tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class|
= link_to tag.name, {:action => :tag, :id => tag.name }, :class => css_class

This Is my controller:

def index
@posts = Post.page(params[:page]).per(5)
tag_cloud< br /> 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

I want to move the tag cloud from the index view to the application layout, but I don’t know how to call the controller action method from there.

In addition, I have a question, this Is MVC safe? Please give me any suggestions.

I am using the gem’act-as-taggable-on’

Code for moving tag_cloude

def tag_cloud
@tags ||= Post.tag_counts_on(:tags)
end

Go to ApplicationHelper and then you can use it <%= tag_cloud%> in your application layout.

In my posts/index view There is this code:

-tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class|
= link_to tag. name, {:action => :tag, :id => tag.name }, :class => css_class

This is my controller:

< pre>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

I want to move the tag cloud from the index view to the application layout, but I don’t know how to call the controller action method from there.

Also, I have a question about this MVC is it safe? Please give me any suggestions.

I am using the gem’act-as-taggable-on’

Code for moving tag_cloude

def tag_cloud
@tags ||= Post.tag_counts_on(:tags)
end

Go to ApplicationHelper and then you can Use it <%= tag_cloud%> in your application layout.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3315 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.