简体   繁体   中英

Ruby on Rails <%= %> within a <%= link_to %>

I'm new with Ruby on Rails. I'm following a guide using haml. I don't like haml so I've skipped using that. The problem is that I'm trying to have my <h2><%= forumthread.title %></h2> link to the forumthread_path.

With haml its set to be: %h2= link_to forumthread.title, forumthread_path

How can I achieve the same result without haml?

Thanks a lot in advance!

I think you just want this:

<h2><%= link_to forumthread.title, forumthread_path(forumthread) %></h2>

Which will generate the same thing as:

<h2><a href="<%= forumthread_path(forumthread) %>"><%= forumthread.title %></a></h2>

See the link_to documentation , the first argument is the 'title' for the link, and the second is the path for the link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM