Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Link with Ruby on Rails

Tags:

Obviously, I am new to this.

I need to make a link using rails to something within the model. The code I have is this. It is probably not even the correct syntax:

<li id="nav_home"><%= link_to 'SOMETHING', {:controller => 'inventories', :action => 'home'} %></li>

This code defaults to creating a text link, but I want the link element to link. Ideally it would output as so:

<li><a href="goes-to-something"></a></li>

Thanks!

like image 972
scarysnow Avatar asked Jan 22 '10 23:01

scarysnow


People also ask

What is routing in Ruby on Rails?

The routing module provides URL rewriting in native Ruby. It's a way to redirect incoming requests to controllers and actions. It replaces the mod_rewrite rules. Best of all, Rails' Routing works with any web server.


2 Answers

The whole point of link_to is that it helps you create links to resources within your application via your routes. If all you want is <li><a href="#"></a></li>, then just use <li><a href="#"></a></li> --- no need to involve link_to.

like image 118
Ben Avatar answered Sep 30 '22 12:09

Ben


<li><%= link_to '', '#' %></li>

But that's a bit nutty. Plain HTML is fine. Or there is link_to_function which will create a link like that but have an onclick that executes some javascript.

Or you can call other helpers in place of your "SOMETHING"

<li><%= link_to image_tag('foo.png'), '#' %></li>

Renders:

<li><a href="#"><img src="/images/foo.png"/></a></li>
like image 28
Alex Wayne Avatar answered Sep 30 '22 11:09

Alex Wayne