Navbar dropdown not working - ruby-on-rails-3

I have the code below, but the dropdown is not working, any ideas?
Do I need to add "$('.dropdown-toggle').dropdown();" to my javascript file?
.navbar.navbar-fixed-top
.navbar-inner
.container
%button.btn.btn-navbar{"data-target" => ".nav-collapse", "data-toggle" => "collapse", :type => "button"}
%span.icon-bar
%span.icon-bar
%span.icon-bar
= link_to I18n.t(:site_title), root_url, :class => "brand"
.nav-collapse
%ul.nav
%li= link_to I18n.t(:nav_thelist)
%li= link_to I18n.t(:nav_themap)
%li= link_to I18n.t(:nav_the92)
%li.dropdown
%a.dropdown-toggle{"data-toggle" => "dropdown", "data-target" => "#", :href => "#"}
= I18n.t(:nav_admin)
%b.caret
%ul.dropdown-menu
%li= link_to I18n.t(:nav_leagues), leagues_url
%li= link_to I18n.t(:nav_clubs), clubs_url
%li= link_to I18n.t(:nav_visits), visits_url

Dropdowns in Twitter-Bootstrap require not only the appropriate attributes and CSS, but also the appropriate javascript plugins. Check here to make sure you have the right javascript plugins installed for dropdowns:
http://twitter.github.com/bootstrap/javascript.html

If you are using twitter-bootstrap-rails gem
it names the require path incorrectly in application.js
Change it to
//= require bootstrap

Related

Haml Bootstrap search form

My navbar code looks like this:
%header.navbar.navbar-fixed-top
%div.navbar-inner
%div.container
%nav
%ul.nav.pull-right
- if user_signed_in?
%li= link_to "Sign out", '#'
- else
%li= link_to "Sign in", '#'
I am trying to get my navbar to look like that in the Bootstrap navbar page as shown here, however I'm not sure how to translate
<form class="navbar-search pull-left">
<input type="text" class="search-query" placeholder="Search">
</form>
into Haml. My last attempt look like:
%header.navbar.navbar-fixed-top
%div.navbar-inner
%div.container
%nav
%ul.nav.pull-right
%form.navbar-search
%input.search-query
- { :type => "text", :placeholder => "Search" }
- if user_signed_in?
%li= link_to "Sign out", '#'
- else
%li= link_to "Sign in", '#'
While the search bar appears with the proper CSS classes, the :type => "text" and :placeholder => "Search" portions do not exist in my html when I inspect it. How can I fix this? Thanks!
== EDIT ==
Perhaps to make this clearer - I'm using this in a rails 3 app and I realize that I should probably be using form_tag, but I'm not sure how to proceed.
It should work like this:
%header.navbar.navbar-fixed-top
%nav.navbar-inner
.container
%ul.nav
- if user_signed_in?
%li= link_to "Sign out", '#'
- else
%li= link_to "Sign in", '#'
= form_tag some_path, :class => "navbar-search pull-left", :method => :get do
= text_field_tag :name, nil, :class => "search-query span3", :placeholder => "Search"
Be careful with the indentation.
I also advise you to try to start with rails app template and tutorial: http://railsapps.github.com/. As for a beginner it would be an excellent example of what and how to set up and how it should look like.

Specifying :class of embedded ruby form

If I would like to assign a class to my embedded ruby form, like so?:
<%= form_for(User.new) do |f|, :class => "form-horizontal" %>
How could I go about doing it? I keep getting a syntax error.
Thanks!
from http://apidock.com/rails/ActionView/Helpers/FormHelper/form_for
form_for(record, options = {}, &proc)
meaning:
<%= form_for(User.new, { :class => 'form-horizontal' }) do |f| %>

Formtastic Collection Select Dropdown

When using formtastic in my rails3 application, I can't get the dropdown menus to work. Instead they appear as a selection list.
My code looks like this:
<%= f.label :slas, "Service" %></td><td><%= f.input :slas, :collection => #slas %>
Is this something I need to change in the css?
Wow, that took some fiddling.
In order to get a single dropdown list, instead of the select box, I needed to do this:
<%= f.label :slas, "Service" %></td><td><%= f.input :slas, :as => :select, :multiple => false, :input_html => { :size => 1 } %>
That was surprisingly hard...
That's strange. :as => :select should have done the trick by itself.

Rendering the Devise edit Password Form

I'm trying to render the Devise edit password form within another view because I don't want to duplicate the edit pw logic.
I've tried the following (after generating the Devise views):
<%= render 'devise/passwords/edit' %>
<%= render 'devise/passwords/form' %>
And a number of other variations on render that all seem to give me the same error:
"ActionView::MissingTemplate in foo#foo
Missing partial devise/passwords/edit..."
This variation:
<%= render :file => 'devise/passwords/edit.html.erb' %>
Gave me some hope but the following error:
"undefined local variable or method `resource' for #<#:0x47ef0e0>"
around this line:
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
That makes me think I'm close (as that is code from the form that I want) but shouldn't that template be using the correct logic from the hidden Devise controller? Or do I need to do something in the routes file to get this to work?
Am I way off?
Try this:
<%= render :template => 'devise/passwords/edit',
:locals => {
:resource => my_user_model_variable,
:resource_name => my_user_model_name } %>
Where:
my_user_model_variable could be current_user
my_user_model_name could be "User"

Rails 2 to rails 3 link_to image_to tag

This is the code that I use in rails 2
<%= link_to_remote image_tag("icon_edit.png", :onmouseover=>"$(this).up('.tooltip-wrapper').down('.tooltip-wrapper-box').show()",:onmouseout=>"$(this).up('.tooltip-wrapper').down('.tooltip-wrapper-box').hide()" ).html_safe, :url => { :controller =>'/resume/contact_detail',:action => 'edit_contact_detail'}, :html => { :class => "link_grey" },:before => "$('edit_contact_link').hide();show_spinner('view_contact_detail','view_contact_detail_spinner')" %>
How can I make it to rails 3 ?
I am new to unobtrusive javascript so someone can help me in converting this ?
I tried using the following :
<%= link_to :url => { :controller =>'/resume/contact_detail',:action => 'edit_contact_detail'}, :remote=>true do %>
<%= image_tag('icon_edit.png', :onmouseover=>"$(this).up('.tooltip-wrapper').down('.tooltip-wrapper-box').show()",:onmouseout=>"$(this).up('.tooltip-wrapper').down('.tooltip-wrapper-box').hide()") %>
<% end %>
But I am missing the :before option :(
Thank you
Instead of using :before as you would do in Rails 2.X, define it as a :onclick.
<%= link_to :url => { :controller =>'/resume/contact_detail',:action => 'edit_contact_detail'}, :remote => true, :onclick => "$('edit_contact_link').hide();show_spinner('view_contact_detail','view_contact_detail_spinner')" do %>
<%= image_tag('icon_edit.png', :onmouseover=>"$(this).up('.tooltip-wrapper').down('.tooltip-wrapper-box').show()",:onmouseout=>"$(this).up('.tooltip-wrapper').down('.tooltip-wrapper-box').hide()") %>
<% end %>
The onclick event should be run before the :remote call.
See my comment on your question as to why the remote part isn't running.