[英]Puts Ruby / Rails text in view
I have an elementary problem. 我有一个基本问题。 I'm sure you can tell by the question that I am somewhat new to ruby and rails.
我敢肯定,您可以通过这个问题告诉我,我对红宝石和铁轨有些陌生。
I have a navigation that I am trying to apply the "active" class to so I can style the active page differently. 我有一个导航,试图将“ active”类应用于该导航,以便可以对活动页面进行不同的样式设置。 I have @cur_page set like this with a before_filter:
我用before_filter这样设置@cur_page:
def cur_page
@cur_page = params['action']
end
I am trying to simply output the text "active", but its not working. 我试图简单地输出文本“ active”,但它不起作用。
<li class="button <%= "active" if @cur_page == "contact" %>"><%= link_to "Contact", :public_contact %></li>
I've also tried: 我也尝试过:
<li class="button <%= puts "active" if @cur_page == "contact" %>"><%= link_to "Contact", :public_contact %></li>
I've checked the instance variable to make sure that it is set, and it is displaying "contact" like I expect. 我已经检查了实例变量以确保已设置它,并且它像我期望的那样显示“联系人”。
Any ideas? 有任何想法吗?
What is the :public_contact
? 什么是
:public_contact
? I would recommend you to use current_page? 我会建议您使用current_page? helper instead of
@cur_page
. helper而不是
@cur_page
。
<li class="button <%= "active" if current_page?(public_contact_path(@contact) %>"><%= link_to "Contact", public_contact_path(@contact) %></li>
Replace public_contact_path(@contact)
to valid route helper. 将
public_contact_path(@contact)
替换为有效的路由帮助器。
I think the problem is with double quotes. 我认为问题出在双引号上。
use 'active' instead of "active" use 'contact' instead of "contact" 使用“活动”代替“活动”使用“联系”代替“联系”
<li class="button <%= 'active' if @cur_page == 'contact' %>"><%= link_to "Contact", :public_contact %></li>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.