javascript - Hartl 3rd ed section 8.2.3 dropdown not working -


when click on "account" link in navbar, dropdown menu not appear. happen # added end of url, users/1 becomes users/1#.

a question dropdown not working has been asked here: ruby on rails chapter 8, 3rd edition. menu dropdown. have tried number of variations application.js file, show below, , far know, sessions_controller.rb , sessions_helper.rb match hartl has.

i using windows , chrome.

i have enabled "show user agent shadow dom" in dev console in chrome , see html dropdown menu. don't see error messages.

i think there either controller error or bootstrap/sass/rails version incompatibility of kind. did dropdown work in hartl 2nd ed chapter 8, don't want roll gems far.

my application.js:

//= require jquery //= require jquery_ujs //= require bootstrap //= require turbolinks //= require_tree . 

i've tried

//= require jquery //= require bootstrap //= require jquery_ujs //= require turbolinks //= require_tree . 

and i've tried subbing bootstrap-sprockets bootstrap.

sessions_helper.rb:

module sessionshelper   def log_in(user)     session[:user_id] = user.id   end    def current_user     @current_user ||= user.find_by(id: session[:user_id])   end    def logged_in?     !current_user.nil?   end end 

i tried replacing !current_user.nil? current_user.nil? didn't work.

sessions_controller.rb

class sessionscontroller < applicationcontroller   def new   end    def create     user = user.find_by(email: params[:session][:email].downcase)     if user && user.authenticate(params[:session][:password])       log_in user       redirect_to user     else       flash.now[:danger] = 'invalid email/password combination'       render 'new'     end   end    def destroy   end end 

gemfile (portion)

gem 'rails', '4.2.2' gem 'bcrypt', '3.1.7' gem 'pg', '~> 0.18.3' gem 'bootstrap-sass', '3.2.0.0' gem 'sass-rails', '5.0.2' gem 'uglifier', '2.5.3' gem 'coffee-rails', '4.1.0' gem 'jquery-rails', '4.0.3' gem 'turbolinks', '2.3.0' gem 'jbuilder', '2.2.3' 

custom.css.scss (first 2 lines)

@import "bootstrap-sprockets"; @import "bootstrap"; 

and finally, _header.html.erb

<header class="navbar navbar-fixed-top navbar-inverse">   <div class="container">     <%= link_to "birder's life list app", root_path, id: "logo" %>     <nav>       <ul class="nav navbar-nav navbar-right">         <li><%= link_to "home",   root_path %></li>         <li><%= link_to "help",   help_path %></li>           <% if logged_in? %>           <li><%= link_to "users", '#' %></li>           <li class="dropdown">             <a href="#" class="dropdown-toggle" data-toggle="dropdown">               account <b class="caret"></b>             </a>             <ul class="dropdown-menu">               <li><%= link_to "profile", current_user %></li>               <li><%= link_to "settings", '#' %></li>               <li class="divider"></li>               <li>                 <%= link_to "log out", logout_path, method: "delete" %>               </li>             </ul>           </li>         <% else %>           <li><%= link_to "log in", login_path %></li>         <% end %>       </ul>     </nav>   </div> </header> 

thanks in advance.

i have solved problem. found post: http://www.erikminkel.com/2013/09/01/twitter-bootstrap-3-in-a-rails-4-application/

and ran

bundle exec rake assets:precompile rails_env=development 

then checked application.js file , found had somehow changed

//= require bootstrap 

to

//= bootstrap 

i know had correct when having problems before, don't think reason dropdown problem.

the railsguide on asset pipeline mentions rake assets:precompile in production environment. have not been able

bin/rake assets:precompile 

to work.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -