views:

144

answers:

4

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!

A: 

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.

Ben
I am linking to a page within the model however?
scarysnow
You need to clear up your question then. You say that your desired output is `<li><a href="#"></a></li>`. Is it?
Ben
Yeah, I was afraid I was being vague. I want to create a relative link within the model. Let's just pretend that the link goes somewhere within the model...
scarysnow
Please update your question with your *actual* erb code, the *actual* output, and the *actual* desired output.
Ben
A: 
<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>
Squeegy
A: 

If you are using JavaScript to make this empty link do something, you don't actually need a link - you can place an event on any HTML element and handle if accordingly.

Toby Hede
A: 

I think you want to look at Rail's RESTful named routes, which provide the various "inventories_path" and "inventories_url" functions. If, in your routes.rb, you have "map.resources :inventories" then you get all these functions for free.

Check out the Rails Guide on Routing. Then you can do something like:

link_to "SOMETHING", inventory_url(@myinventory)
Paul Fedory