0

I want to create a link_to render :partial. I have two partials stored already in the view folder in which I call the link_to (which is the profiles views). Getting the JavaScript to load the data is the next step but I am having trouble structuring the link_to properly.

Here's what I had:

<ul id="infoContainer">
  <li><%= link_to render(:partial => "about") do %>About<% end %></li>
  <li><%= link_to render(:partial => "other") do %>Other<% end %></li>
</ul>

Using these, both partials rendered in my show.html.erb and the links disappeared.

So I tried the following:

<ul id="infoContainer">
  <li><%= link_to render(:partial => 'about'), :class => "a", :remote => true do %>About<% end %></li>
  <li><%= link_to render(:partial => 'other'), :class => "o", :remote => true do %>Other<% end %></li>
</ul>

Both partials still show and the "About"/"Other" text links still don't show.

UPDATE: So I may have the link_to working. It's just not rendering anything. Gotta fix that with JavaScript I assume.

<li><%= link_to "About", (:partial => 'about'}, {:class => "a"}, :remote => true %></li>
<li><%= link_to "Other", (:partial => 'other'}, {:class => "o"}, :remote => true %></li>

Using the link_to above makes the URL: /profiles/1?partial=about

tvalent2
  • 4,959
  • 10
  • 45
  • 87
  • 1
    When using the block form of `link_to` as you are, the first argument is expected to be a URL or an ActiveRecord object, or an options hash. However, you're passing it the result of `render`, which returns a rendered view. Do you want the view returned by that `render` to be the body of that link? – Jordan Running Oct 17 '11 at 05:55
  • No, I want the body of the link to just be the word for the link. Then when you click it the view should be the partial. – tvalent2 Oct 17 '11 at 13:37
  • Just updated my question. That seems to be working... – tvalent2 Oct 17 '11 at 20:58

2 Answers2

3

you're using link_to incorrectly -- please check the API / docs

it's called either:

link_to(body, url, html_options = {})
  # url is a String; you can use URL helpers like
  # posts_path

link_to(body, url_options = {}, html_options = {})
  # url_options, except :confirm or :method,
  # is passed to url_for

link_to(options = {}, html_options = {}) do
  # name
end

link_to(url, html_options = {}) do
  # name
end

See:

http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to

and perhaps:

link_to syntax with rails3 (link_to_remote) and basic javascript not working in a rails3 app?

Community
  • 1
  • 1
Tilo
  • 33,354
  • 5
  • 79
  • 106
0
<ul id="infoContainer">
  <li><%= link_to render(:partial => 'about'), urlyouwant %></li>
  <li><%= link_to render(:partial => 'other'), urlyouwant %></li>
</ul>

If you want to run javascript when user click on, you can read more at http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#method-i-link_to_function

<ul id="infoContainer">
  <li><%= link_to_function render(:partial => 'about'), "alert('About!')" %></li>
  <li><%= link_to_function render(:partial => 'other'), "alert('Other!')" %></li>
</ul>
KingOfDCP
  • 13
  • 5