I have this dropdown list:
- if current_user
%li.header__list-item.dropdown
%a.dropdown-toggle{:href => "#", "role" => "button", "data-toggle" => "dropdown", "data-target" => "#"}
Account
%b.caret
%ul.dropdown-menu{"role" => "menu"}
%li
= link_to "Change your password", edit_user_registration_path
%li
= link_to t('devisegeneral.sign_out'), destroy_user_session_path, method: :delete, class: 'header__link header__link--active'
- else
%li.header__list-item
= link_to t('devisegeneral.sign_in'), new_session_path(:user), class: 'header__link header__link--active'
so that when a user clicks in Account, these two links change your password and sign_out should appear. But instead like this I have them both displayed all the time and the "button" account doesn't work. Is there anything I am missing, because I am loosing a lot of time and can't fix this.
I'd recommend using this template instead of yours:
https://www.w3schools.com/CSS/css_dropdowns.asp
I have used it multiple times and It works great!
Related
I'm working on a html slim file for a Ruby on Rails project. I want to create a button of class btn btn-primary (I'm using bootstrap) for a controller action. Name of controller is default_responses and action is edit. So I first did:
= link_to 'Test this', :controller => 'default_responses', :action => 'edit', :id => params[:id].to_i
This would become
Test this
where 7 is the id parameter and is correct for my case. However, it is not a button at all, just an anchored tag. It also redirects me to the correct page.
Then I tried
= link_to 'Test this', :controller => 'default_responses', :action => 'edit', :id => params[:id].to_i, class: 'btn btn-primary'
which gave me
Test this
This is still not what I want as it is not a button still.
Also tried = link_to 'Test this', :controller => 'default_responses', :action => 'edit', :id => params[:id].to_i, :class=> 'btn btn-primary'
It returned Test this which is still wrong.
Any suggestions? Thanks.
Rails' link_to takes multiple hash options, in your example you're supplying a single hash option, which all get passed into the url_options section. You'll need to add the curly brackets ({}) around the first hash to tell ruby which option goes to which hash.
= link_to 'Test this', { :controller => 'default_responses', :action => 'edit', :id => params[:id].to_i }, class: 'btn btn-primary'
should work. Of course, you could also use a url helper (url_for, default_responses_path, etc) instead of the first hash.
Maybe this question is similar to others but I seriously can't find any solutions looking at others questions answers
, I have a form in my view
<%= form_tag list_campaigns_path, :method => 'get', :id => "country_search" ,remote: true do %>
<%= select_tag "search_by_country", options_for_select(#country.collect { |country|
[country.name] }, params[:search_by_country]),{ prompt: "Select country" ,id: "select_country"} %>
<%= submit_tag "search", class: "btn grn btn-yel"%>
<% end %>
what I'm trying to do is that when someone selects a country from dropdown say he selects US then after hitting on search button that selected country will be listed below with other search results that this is the country with you have performed your search.
just a info:- i'm using country_select gem for getting countries list in dropdown
To display the selected value, you have to use:
:selected => :search_by_country
in your options_for_select.
So, change your select_tag to this:
<%= select_tag(:search_by_country, options_for_select(#country.collect { |country|
[country.name] }, selected: params[:search_by_country]), { prompt: "Select country", id: "select_country" })%>
This is weird! I have an html.erb form, and in this form I have a button that links the user to an action in another controller (finance_extensions) to print pdf. This is working great, but the thing is that I need my own action that I'm using in the current controller (parent_wise_fee_payments), so I added this same action + view file to my controller and I changed this in pay_all_fees.html.erb:
<%= link_to "► #{t('print_receipt')}",
{:controller => "finance_extensions", :action => "pay_all_fees_receipt_pdf", :id => student.id}, :target => '_blank', :class => 'user_button' %>
to this:
<%= link_to "► #{t('print_receipt')}",
{:controller => "parent_wise_fee_payments", :action => "pay_all_fees_receipt_pdf", :id => student.id}, :target => '_blank', :class => 'user_button' %>
This causes the button to disapper. I also tried adding a test action and view in my controller, and tried removing " :controller" but it didn't solve my problem.
Is this weird or am I missing something here?!
Did you add your new action to the auth file in the config??
I'm trying to get this simple list working, but the ul is closing and not enclosing the li elements in the loop. Am I missing a simple way to do this?
%ul.nav.nav-tabs.nav-stacked
- #courses.each do |c|
%li
= link_to "add", { :controller => "admin/relateds", :action => "edit", :id => c.id }, :confirm => "Are you sure?"
= c.coursetitle
The %li needs indentation because it is within a do block. Even if it is valid markup it will save you debugging time if you opt to use 2 or 4 spaces for indentation for better legibility, as one is very difficult to discern.
%ul.nav.nav-tabs.nav-stacked
- #courses.each do |c|
%li
= link_to "add", { :controller => "admin/relateds", :action => "edit", :id => c.id }, :confirm => "Are you sure?"
= c.coursetitle
you need to indent the %li and what's supposed to be inside. Currently your loop does nothing.
Anyone know if you can assign a tag and class to the disabled or current link? The example below only displays as plain text in the browser for the current link.
I have a bit of rails code displaying a list of buttons for each design in the database.
<% #id_cards.each do |id| %>
<%= link_to_unless_current id.design_type, id_card_design_path(id.id), :class => 'btn' %>
<% end %>
The active links are assigned the correct class and display as buttons.
link_to_unless_current accepts a block which can be used to override the default behavior.
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to_unless_current
<%=
link_to_unless_current("Comment", { :controller => "comments", :action => "new" }) do
link_to("Go back", { :controller => "posts", :action => "index" })
end
%>
In the example above it would yield the 'Go back' link if the current page was the 'new comment' page.
#James gave proper answer its just you are too young to take it right :)
<% #id_cards.each do |id| %>
<%=
link_to_unless_current(id.design_type, id_card_design_path(id.id), :class => 'btn') do
content_tag(:p, id.design_type, :class => :some_class
end
%>
<% end %>