Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialChris Yoo
4,837 PointsRails: trouble with using link_to and f.check_box under dropdown menu and under form_for.
I am trying to add a check_box(remember me?) and a link_to(forgot your password?). However, the check_box and the link_to won't get clicked. (the check_box and the link_to is under dropdown menu which is under form_for. So, I suspect it doesn't work because those are under dropdown menu and form_for, but I don't know exactly how to solve it.)
Any help will be appreciated. Thanks!! :)
Here is the simplified code:
<%= form_for :user, url: {controller: "navbar", action: "create"}, :html => {:id => "login_form"} do |f| %>
<button class="button dropdown-toggle" data-toggle="dropdown" type="button">
Login
</button>
<ul class="dropdown-menu">
<span>
<%= f.label "Remember me? " %>
</span>
<span>
<%= f.check_box :remember_me %>
</span>
<span>
<%= link_to("forgot your password?", {:controller => 'password_reset', :action => 'new'}, :id =>'forgot_your_password') %>
</span>
<a class="login_dropdown button button-blue" onclick=" $('#login_form').submit();">
<span>
Log In
</span>
</a>
</ul>
<% end %>
2 Answers
Maciej Czuchnowski
36,441 PointsUL usually needs its elements to be LI (list items). Try using them instead of SPANs. Also, see if they would work without the dropdown-menu.
thomascawthorn
22,986 PointsHey Chris,
This might be a css z-index issue. When you click the drop down button, can you see the link, but you can't click on them?
I would definitely suggest using <li></li> tags instead of span tags for more semantic html markup. You could also use a <div></div> instead of using an unordered list.
Hope this helps
Chris Yoo
4,837 PointsYes, I see the link but I cannot click the link using the left click. But I can go to the link by using right click, and then clicking "open link in new tab" or "open link in new window".
thomascawthorn
22,986 PointsIf Z-index is the issue, I don't think you should even be able to right-click on the link. Concentrate on what Maciej Czuchnowski mentioned - it sounds more like a javascript bug!
Chris Yoo
4,837 PointsOkay, thank you very much!
Chris Yoo
4,837 PointsChris Yoo
4,837 PointsWithout dropdown menu it does work. But replacing <li> doesn't seem to help :(
Maciej Czuchnowski
36,441 PointsMaciej Czuchnowski
36,441 PointsOK, so I guess you just can't have such elements in dropdown menus...or you'd need to implement that dropdown menu in some other way, for example as a hiding/showing div using jQuery.
Chris Yoo
4,837 PointsChris Yoo
4,837 PointsThank you. Only if I knew more rails, I would try other ways, unfortunately, I don't know much about it :( Do you have any alternate ways?
Maciej Czuchnowski
36,441 PointsMaciej Czuchnowski
36,441 PointsThis is not so much a Rails thing - you should check the jQuery course (in JavaScript library of courses) on Treehouse and look for inspiration there, it shows you a lot of cool stuff that you can do in your apps, this also works in Rails apps.
Chris Yoo
4,837 PointsChris Yoo
4,837 PointsYes, I will do that. Thanks for your help!