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.
Related
I'm trying to create inline radio buttons which also has its label inline (at the very left).
As I state in the title, using Bootstrap and SimpleForm.
My code looks like this:
<%= f.input :breakdown_or_size,
:collection => ["Breakdown", "Manual"],
:as => :radio_buttons,
:item_wrapper_class => 'inline',
:label => 'Select One: ' %>
This is what I get:
(source: webpagescreenshot.info)
I looked high and low for simple_form_for help. In the end I couldn't find anything, but at least with form_for you can do this:
<%= form_for(#book) do |f| %>
<% if #book.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#book.errors.count, "error") %> prohibited this book from being saved:</h2>
<ul>
<% #book.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="actions", style='inline'>
<%= f.label 'Select One: ' %>
<br/>
<%= f.radio_button :collection, "Breakdown" %> Breakdown
<%= f.radio_button :collection, "Manual" %> Manual
<br/>
<%= f.submit %>
</div>
Which at least solves the inline rendering.
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) %>
I am trying to add a user icon to my header. bootstrap is adding more icons than what my code calls for, what is going on? Thanks in advance!
<ul class="nav pull-right">
<% if user_signed_in? %>
<li><%= link_to "Edit Profile", edit_user_registration_path %></li>
<li><%= link_to "Logout", destroy_user_session_path, method: :delete %></li>
<% else %>
<li><%= link_to "", new_user_session_path, class: "icon-user" %></li>
<% end %>
</ul>
http://i.minus.com/i7krj72G9Gmsd.png
i am using the responsive navbar btw.
I don't have the bootstrap icons in my rails project to test this, but see if this works:
<%= link_to raw("<i class='icon-user'></i>"), new_user_session_path %>
You can set padding:15px 15px 15px to padding:0 for .navbar .nav>li>a in your CSS.
I am confused by the addition of [:session] to params. It also seems to break my website. Can someone please explain what this does for me?
class SessionsController < ApplicationController
.
.
.
def create
user = User.find_by_email(params[:session][:email])
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_back_or user
else
flash.now[:error] = 'Invalid email/password combination'
render 'new'
end
end
.
.
.
end
Error message:
1) Authentication signin with invalid information
Failure/Error: before { click_button "Sign in" }
NoMethodError:
undefined method []' for nil:NilClass
# ./app/controllers/sessions_controller.rb:7:increate'
# (eval):2:in click_button'
# ./spec/requests/authentication_pages_spec.rb:18:inblock (4 levels) in '
EDIT 8/2
I believe the problem is related to a switch from form_for to form_tag. I lost the reference to sessions in the switch because I could not figure out how to properly include it. If anyone has any advice on this issue it would be most appreciated. I am wondering if there is a practical reason for wanting it to be params[:session][:email] instead or is it just for organization?
new.html.erb
<% provide(:title, "Sign in") %>
<h1>Sign in</h1>
<div class="row">
<div class="span6 offset3">
<%= form_tag sessions_path do %>
<%= label_tag :email %>
<%= text_field_tag :email %>
<%= label_tag :password %>
<%= password_field_tag :password %>
<%= submit_tag "Sign in", class: "btn btn-large btn-primary" %>
<% end %>
<p>New user? <%= link_to "Sign up now!", signup_path %></p>
</div>
</div>
Try removing the [:session] brackets, that worked for me
It brakes your code 'cos the params[:session] is nil I think and you trying to get [:email] from nil, what ofcourse should cause the exception. There should be some code in tutorial that defines params[:session] hash. Try to look better.
To make your code stable you have to be sure that params[:session] is always defined or try to use ternar function params[:session] ? params[:session][:email] : ''
You can replace this in your view :
<%= form_for :session, :url => sessions_path do %>
<%= label_tag :email %>
<%= text_field_tag :email %>
<%= label_tag :password %>
<%= password_field_tag :password %>
<%= submit_tag "Sign in", class: "btn btn-large btn-primary" %>
<% end %>
form_tag generate just an HTML form tag and form_for is used to describe something. All the inputs for a field of a form create with form_for will have a name like this : user_session[email]. So, when you submit the form, in your controller, you will have this : params[:user_session][:email].
I have a Post which can have multiple Tags, each of which relates to a User (think Facebook tagging).
In my Post form I have this Formtastic code:
<%= f.inputs :class => 'tags' do %>
<ul>
<%= f.semantic_fields_for :tags do |t| %>
<% if t.object.new_record? %>
<%= t.input :user_id, :label => " ", :input_html => { :class => 'chosen', :'data-placeholder' => 'Select connection' }, :as => :select, :collection => current_user.connections %>
<% end %>
<% end %>
</ul>
<% if #post.tags.present? && !#post.new_record? %>
<ul class="existing-tags">
<%= f.fields_for :tags do |t| %>
<% unless t.object.new_record? %>
<li>
<%= link_to avatar(t.object.user), user_path(t.object.user) %>
<%= t.check_box :_destroy %>
<%= t.label :_destroy, 'Remove' %>
</li>
<% end %>
<% end %>
</ul>
<% end %>
<% end %>
As you can see this can allow a tag to be added one at a time. However I'd like to allow multiple selections in the dropdown menu, to create multiple tags in one go. Adding "multiple" doesn't work, however: it simply results in creating a tag for the current user, posting the Post.
Can anyone suggest a way I can use a single select field to create multiple tags?
A bit late to the party, but I solved this problem using the awesome jQuery Chosen plugin which makes multiple selects look really good.