Rails link_to in templates - ruby-on-rails-3

When I add a link_to to a pre-made bootstrap template it ends up putting the link below the nav-icon. I'm not sure if this is a CSS problem or if my code is wrong.
<li><i class="icon-off icon-white"></i><%= link_to('Logout', destroy_user_session_path, :method => :delete) %></li>

Try this
<%= link_to("<i class='icon-off icon-white'></i> Logout".html_safe, destroy_user_session_path, :method => :delete) %>

Related

html inside link_to rails is not working

I´m new with ruby and I´m trying to insert an awesome-font icon inside a link using rails 3.2.15
This is my code
<%= link_to tweet_path(tweet), method => :delete, :confirm => 'Are you sure?' do %>
<i class="icon-trash"></i>
<% end %>
<%= link_to edit_tweet_path(tweet) do %>
<i class="icon-pencil"></i>
<% end %>
I don´t know what I'm doing wrong.
Thank you in advance.
You can do this:
<%= link_to raw('<i class="icon-trash"></i>'), tweet_path(tweet), method => :delete, :confirm => 'Are you sure?' %>
you can do this:
<%= link_to content_tag(:i,nil, :class => "icon-trash"), tweet_path(tweet), method => :delete, :confirm => 'Are you sure?' %>
<%= link_to content_tag(:i,nil, :class => "icon-pencil"), edit_tweet_path(tweet) %>
hope this helps you

Devise invitable show inviter name or email

I want to be able to show the user that sent out the invitation rather than just my domain when sending out a devise invitation but haven't been able to find any documentation on this.
The two places where I need to show this name are in the invitation email-
(in place of 'Someone')
<p>Hello <%= #resource.email %>!</p>
<p>Someone has invited you to <%= root_url %>, you can accept it through the link below.</p>
<p><%= link_to 'Accept invitation', accept_invitation_url(#resource, :invitation_token => #resource.invitation_token) %></p>
<p>If you don't want to accept the invitation, please ignore this email.<br />
Your account won't be created until you access the link above and set your password.</p>
and the set password page.
<h4>You're seeing this page because someone has invited you to the site</h4>
<%= simple_form_for resource, :as => resource_name, :url => invitation_path(resource_name), :html => { :method => :put } do |f| %>
<%= devise_error_messages! %>
<%= f.hidden_field :invitation_token %>
<div class="row">
<div class="signup_well span3 offset1">
<legend><%= t 'devise.invitations.edit.header' %></legend>
<%= f.input :password %>
<%= f.input :password_confirmation %>
<%= hidden_field_tag :token_key, resource.invitation_token %>
<%= f.submit t("devise.invitations.edit.submit_button") %>
<% end %>
</div>
I may over looking any documentation on the best approach to do this. Your help saves a lot of frustration. Thank you.
This should works: <%= #resource.invited_by.first_name %>.

Button_to with text and image rails 3

How to create a button with label and image in Rails3?
This code only show an image:
<%= link_to image_tag("newRevision.png"), {:controller => :review_transitions, :action => :show_step}, {:class => "navBtn"} %>
but... the image with text?
<%= link_to "example_text"+image_tag("newRevision.png"), {:controller => :review_transitions, :action => :show_step}, {:class => "navBtn"} %>
thanks!
I think it may be something along these lines
<%= link_to image_tag('image/someimage.png') + "Some text", some_path) %>

rails bootstrap icon in a link to

I'm trying to use one of the icons in Bootstrap for a link_to.
These don't work::
<% link_to '<i class="icon-pencil"></i>', task_path(task)%>
<% link_to task_path(task), html_options = {:class => 'icon-pencil'} %>
I would appreciate the help!
You can use this other form of the link_to helper:
<%= link_to task_path(task) do %>
<i class="icon-pencil"></i>
<% end %>
Make sure to include the = sign before the link_to call.

Rails 3 link_to partial structure

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
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?
<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>