I would like to combine 2 commands into 1, if its possible.
<%= render :partial => 'shared/logo' %>
<%= link_to 'Dashboard', root_url %>
I would like to call the logo in the shared directory and have it be a link at the same time.
How would I write this?
This should do it:
<%= link_to render(:partial => 'shared/logo'), root_url %>
Related
Hello I have this link_to and I can't figure out how to wrap a block of html code in it such that the div inside the link_to becomes a link. I have this code:
<%= link_to #favorites[0].name, {:controller => "events", :action => "search", :category => #favorites[0].name} %>
I have tried using "do" then <%end%> but I can't make it work.
<%= link_to #favorites[0].name, {:controller => "events", :action => "search", :category => #favorites[0].name} do %>
<div> CODE HERE</div>
<%end%>
Any ideas on how to do this? I do not understand the syntax.
You need to give only path with link_to when using the block.
<%= link_to({:controller => "events", :action => "search", :category => #favorites[0].name}) do %>
<div>
<%= #favorites[0].name %>
</div>
<%end%>
i want to show an small icon instead of a textlink.
using this piece of code:
<li>
<%= link_to '', :class => 'nav-icon' do %>
<span class="icon-home">Home</span><%= root_path %>
<% end %>
</li>
but rails now shows me the icon followed by a /
is there any way to avoid that behavior?
<li>
<%= link_to root_path, :class => 'nav-icon' do %>
<span class="icon-home">Home</span>
<% end %>
</li>
The / displayed after your icon is generated by <%= root_path %>.
<%= %> seems:
please ruby, write this on my html.
so ruby wrote your root_path variable, and your root_path is equal to /.
remove your <%= root_path %> after <span class="icon-home">Home</span> and everything will be ok.
Following should work
<li>
<%= link_to '', :class => 'nav-icon' do %>
<span class="icon-home">Home</span>
<% end %>
</li>
Reason: the / is coming due to this code <%= root_path %>
and writing just <%= link_to '', :class => 'nav-icon' do %> will create link with empty href
I think you should give your path in the first argument of link_to as follows
link_to(url, html_options = {}) do
# your icon code
end
I followed the source code form the rails3-devise-bootstrap-example to get my devise-login-page (that normally - without AJAX - works fine) in a popup window.
When I click on the login link nothing happens. The logfile tells me
Started GET "/facebox/fb_login" for 127.0.0.1 at 2014-01-09 19:15:0
Processing by FaceboxController#fb_login as JS
Rendered devise/shared/_links.erb (3.0ms)
Rendered devise/sessions/_new.html.erb (1155.0ms)
Rendered facebox/fb_login.js.erb (1251.0ms)
Completed 200 OK in 1509ms (Views: 1508.0ms | ActiveRecord: 0.0ms)
But no login-pop-up-window appears.
Here is the login link in my index.html.erb file
<%= link_to 'Login', fb_login_path, :remote => true %>
That starts my fb_login.js file
$.facebox('<%= escape_javascript(render :partial => 'devise/sessions/new') %>')
and should open _new.html.erb that looks like this:
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<div class="form-inputs">
<%= f.input :email, :required => false, :autofocus => true %>
<%= f.input :password, :required => false %>
<%= f.input :remember_me, :as => :boolean if devise_mapping.rememberable? %>
</div>
<div class="form-actions">
<%= f.button :submit, "Sign in" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
but it doesn't. What went wrong?
I got the answer by myself . Under assets/javascripts I had to define
jQuery ->
$('a[rel*=facebox]').facebox()
# facebox - make modal
$(document).bind "loading.facebox", ->
$(document).unbind "keydown.facebox"
$("#facebox_overlay").unbind "click"
in a js.coffee file.
I've been running my head into a wall for hours now and I can't make this work. I'm trying to add a bunch of check boxes to verify items on my index page. I found this old rails cast that does exactly what I want to do, but I've run into a problem. Anything enclosed inside my form is removed from the index page, like just gone poof. Here's the code from the index view.
<% form_tag verify_products_path, :method => :put do %>
<% #products_unverified.each do |products| %>
<% if product.deleted != 'true' %>
<tr data-link="<%= product_path(product) %>">
<td><%= product.name %></td>
<td><%= product.description %></td>
</tr>
<% end %>
<% end %>
<%= submit_tag "Mark as Verified" %>
<% end %>
</tbody>
Here's the routes stuff
resources :products do
put :verify, :on => :collection
end
and the controller just has a dummy method for now.
def verify
end
Any clue as to why the index view blanks out when the form is introduced? Any help is much appreciated.
You forgot the = before form_tag:
<%= form_tag verify_products_path, :method => :put do %>
put an = in front of form_tag
instead of
<% form_tag verify_products_path, :method => :put do %>
try
<%= form_tag verify_products_path, :method => :put do %>
Ruby on Rails:
I'd like the <%= render 'shared/intro_form' %>
to render a form for every user row displayed by <%= render #users %>
I know that I'll need to embed the former line in the latter somehow, perhaps with an "each...do" statement, but I'm having trouble figuring out the right syntax. Thanks!
<% provide(:title, 'All users') %>
<h1>All users</h1>
<%= will_paginate %>
<ul class="users">
<li><%= render #users %></li>
<li><%= render 'shared/intro_form' %></li>
</ul>
<%= will_paginate %>
http://guides.rubyonrails.org/layouts_and_rendering.html
3.4.5 Rendering Collections
<%= render :partial => "shared/intro_form", :collection => #users %>