简体   繁体   中英

Can anyone show me how to make links markup in Rails3?

I'd like to make link markups something like this

User List / User A / Blog

It could be something like this also User List / User A / Profile

User List could be Model.
User A would be given by parameter
Blog or Profile would be an action(Method)

How can I pass these information to view from my controller if view was something like this. you can obviously modify!! Thanks

          <ul class="breadcrumb">
          <li>

          <% if !@FirstDirPath.nil? %>
          <%= @FirstDirPath %> <span class="divider">/</span>
          <% end %>

          <% if !@SecondDirPath.nil? %>
          <%= @SecondDirPath %> <span class="divider">/</span>
          <% end %>

          <% if !@ThirdDirPath.nil? %>
          <%= @ThirdDirPath %> <span class="divider">/</span>
          <% end %>

          <% if !@FourthDirPath.nil? %>
          <%= @FourthDirPath %> <span class="divider">/</span>
          <% end %>        

          </li>
          </ul>

Use link_to helper in your views. For example:

<%= link_to "My link", "link_url" %>

For your AR records you can use this syntax:

<%= link_to "Profile", user %>
<%= link_to article.title, article %>
# ... etc.

UPD

I don't understand what you want to do. In views you can use instance variables that defined in actions. For example:

@links = [
  { label: "My link",      destination: some_path },
  { label: "Another link", destination: "path/path" },
  { label: "Third link",   destination: third_list_path }
]

Than in views you can:

<% @links.each do |link| %>
  <%= link_to link[:label], link[:destination] %>
<% end %>

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