I have two Facebook Login buttons in different parts of my website.
The buttons are identicals but one is working fine and the other one not.
When I click on the broken button, a url is concatenated automatically, doesn't matter what is the value for url param on the link_to function that renders the button.
The URL concatenated is auth/facebook, that is where I should go when clicking the button, but I should have set it as the URL param on link_to and not the rails putting it automatically.
Fine button:
<%= link_to "Entrar com Facebook", url_for(root_url+'auth/facebook'), class: "btn btn-facebook btn-block apoiar", id: "facebook_btn" %>
Broken button:
<%= link_to "Cadastrar com Facebook",url_for(root_url+'auth/facebook'), class: "btn btn-facebook btn-block apoiar btn-lg", id: "facebook_btn" %>
If I left the link_to URL param empty It works fine, but this is not the way the omniauth gem docs tells me to do and the other button is working fine...
I'm using facebook omniauth gem.
Related
In My Rails 5 Web App. I have installed Devise gem in it. When I wan to edit my password by clicking on link below but instead on going to the page for update password. Page get refreshed and It gives alert message you are already logged in .
I am using Below link in my Application:
<%= link_to('Edit Password' , edit_user_password_path)%>
Routes Files is as:
devise_for :users, controllers: { sessions: "users/sessions" }
Please suggest me the changes to redirect to edit password page all other links like below are working.
<%= link_to('Edit Registration',edit_user_registration_path )%>
<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>
<%= link_to('Edit Registration', edit_user_registration_path) %>
<%= link_to('Edit Password', edit_user_password_path) %>
I'm simply trying to construct a link_to with method: :delete to call the destroy method in my users controller:
<%= link_to 'disable token', user_path(user), method: :delete, data: { confirm: 'Are you sure?'} %>
Which generates HTML that looks like:
<a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/users/6">disable token</a>
My application.js file has:
//= require jquery
//= require jquery_ujs
And, in fact, i know the javascript is loaded and doing what it is supposed to, because it generates the 'Are you sure?` alert dialog.
However, when following the link I get the following:
No route matches [POST] "/users/9"
And indeed there is no such route, because my only routes are:
users_path GET /users(.:format) users#index
user_path DELETE /users/:id(.:format) users#destroy
The mystery (to me) is WHY is Rails doing a POST to this route in the first place? You'll note that the URL is correct ("/users/9") but that the HTTP verb is not: POST.
The parameters of the request are getting set:
{"_method"=>"delete",
"authenticity_token"=>"VcAVJF1/f9mwjNI4GPteRtDiyjKobnioF0hIQvF+3BVMzUnIoHymM2Z3w2sqSLJqJ11sZ/tIHt78aA9
}
Here you can see the _method key being set to delete as it should be, so why the routing error?!?
I'm stumped.
Edit: If i change my link_to call to include remote: true Rails routes it to the proper route! So, as a "fix" for this i've changed my controller to use UJS, but i don't like this because, well, as far as I can tell what i had before should work!
Here is the link_to call which sends a proper DELETE request as JS:
<%= link_to 'disable token', u, method: :delete, data: { confirm: 'Are you sure?'}, remote: true %>
Just try explicitly stating the controller action and method also (note #user.id is an example, you may be referencing it differently) with url_for:
<%= link_to 'disable token', url_for(action: :destroy, id: #user.id), method: :delete, data: { confirm: 'Are you sure?'} %>
My suspicion in this case is that there is some other javascript that is overriding the rails behavior.
I had the same issue (but with it getting a GET request, rather than POST). It turned out to a completely unrelated bit of JS that was too general in the selector, and was calling jquery's stopPropagation on all anchor tags surrounding a button, which was how my particular HTML was set up.
I am a beginner to Rails. Was working along with Railsguide for Rails 4.
One confusion i have is:
for adding a link , somewhere it is written like:
<h1>Hello, Rails!</h1>
<%= link_to "My Blog", controller: "posts" %>
whereas somewhere its like
<%= link_to 'New post', new_post_path %>
Please clarify the difference.
Good question. Both of these are link helpers, and both are resource-oriented (check out the Rails UrlHelper docs for more information).
The first one will render a link that is associated with the particular controller:
<%= link_to "My Blog", controller: "posts" %>
<a href='/posts'>
The second will render the Rails path specific to creating a new Post object (this is also resource-oriented). Check out section 2.3 in the Rails routing guide:
<%= link_to 'New post', new_post_path %>
<a href='/posts/new'>
I cannot for the life of me figure this out. I have a calendar link that displays the previous (and next) month.
This was built right off of screencast #213 with Ryan Bates as a starting point.
I am trying to have the previous and next links display as buttons. Here is the code for the link to "previous" month ("next" month is the same)
<%= link_to "Previous", date: #date.prev_month %>
now there is also a new event path which I did turn into a button, code below.
<%= link_to 'New Event', new_event_path, class: "btn btn-small btn-info" %>
Adding the same button code does not work on the "previous" and "next" links. I am relatively new to this stuff but it seems it has to do with the "date:" part and how the link is being created to previous and next month.
Can anyone make a suggestion how to get this to display as a button while still functioning the same, or how to achieve the same functionality while displaying as a button?
I think you need to add curly brackets, since the link_to helper expects 2 hashes after the name. This should work:
<%= link_to "Previous", { date: #date.prev_month }, { class: "btn btn-small btn-info" %>
Here's a resource that should be able to help you with this issue: http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to
I would play around with your next/previous links and check out the HTML that gets generated. Also, you can right click the browser page and select "inspect element" in chrome. That will help you debug the CSS.
Hope this helps!
I've been having this annoying problem in which I click over a select dropdown input of my custom form, styled with Zurb Foundation 4 in my Rails application, and the list won't show its elements.
I thought at a start that was a problem with simple form, but I changed the f.association for f.collection_select, my code looks like this:
<h2><%= I18n.t(".sign_up") %></h2>
<%= simple_form_for(resource, :html => {:class => "custom"}, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= f.error_notification %>
<%= devise_error_messages! %>
<%= f.input :rut %>
<%= f.input :name %>
<%= f.input :email %>
<div>
<%= f.label :supplier_type_id %>
<%= f.collection_select :supplier_type_id, SupplierType.all, :id, :name %>
</div>
<%= f.input :password %>
<%= f.input :password_confirmation %>
<%= f.error :base %>
<%= f.submit I18n.t(".sign_up"), :class => "button" %>
<% end %>
<%= render "devise/shared/links" %>
The most strange thing is that sometimes I'm able to see the items when refreshing the page, but when I get to the page navigating from other view of the app then it won't work. I've also noticed this when using hints for forms (i.e: If I have two hints in the same form, in different inputs, only one would show, but the same one message displays in both inputs when each message should show in their respective input. When reloading the page sometimes it shows one hint, and sometimes the other)
The styling looks good, so I think that it might be a foundation javascript problem.
Another thing I've noticed is that when I load the page the styling does a kind of "blinking" when using custom forms. This blinking it looks likes foundation takes a while to load the styling, I've also noticed this on their own custom form documentation site. This may indicate that is a form styled with javascript events or something similar, so this might mean that javascript is working well.
In addition, the checkboxes are having a similar problem, they only can be checked just when you reload the page, it might have some relation with this problem.
I'm very lost, some help would become very handy. Thanks!
--edit: Foundation 5 doesn't include custom forms and works better--
You might need to refresh dropdowns on each page:change event. Try something like this:
$(document).on("page:change", function() {
// SELECTOR_TO_CUSTOM_DROPDOWNS should select any Zurb custom dropdowns you
// are using.
$(SELECTOR_TO_CUSTOM_DROPDOWNS).trigger("change");
});
That's from the documentation on Zurb custom form JS.
Yes, this is caused by turbolinks. It stops $(document).ready from firing on page load, which is required by foundation's custom forms.
Using ssorallen's answer and to be more unobtrusive than the OPs, add this to application.js:
$(function(){ $(document).foundation(); });
$(document).on("page:change", function() {
if ($('form.custom').length > 0) {
$(document).foundation('forms');
}
});
Also, if you have jquery/coffeescript that relies on document ready being fired, add jquery turbolinks to your Gemfile.
Ok, so I just figured out that I have repeated asset load on my browser. This is causing a javascript error. It appears that deleting in the manifest
//= require turbolinks
Solves the problem.
I solved my multiple asset problem changing
<%= javascript_include_tag "application" %>
To the head in my application layout.
After watching the turbolinks railscast I noticed that besides my multiple asset loading, turbolinks and foundation 4 may not be compatible, it might be a solution on this post. But still doesn't work perfect for me.
I also noticed that navbar is also affected by turbolinks.
I think that this is rather a turbolinks problem and not an specific foundation dropdown. I will close this question and open a new on turbolinks and foundation.
Thanks to some Nick Reed insights I found out that the foundation gem was initializing foundation in application.js like this:
$(function(){ $(document).foundation(); });
So I checked the docs and I used this:
<script>
$(document).foundation();
</script>
After the "/body" tag in the application layout and everything seems to be working like a charm!