To signing out a user i have the link :
link_to "Sign out", signout_path, method: "delete"
this link work fine and i have already a route /signout in my routes file, but when i disable javascript and click this link it says : No route matches [GET] "/signout", what's the problem here ?
Without scripting, browsers can only send a non-GET request by submitting a form -- clicking a link is always a GET. When you specify a different method for link_to, it adds a JavaScript hook to the link that dynamically creates and submits a form with the appropriate method. If scripting is disabled, the browser just submits a GET request as it normally would. This is explained in the docs here (look under Options).
If your app needs to support users with scripting disabled, you can use button_to instead of link_to, and style the button to look like a link.
Related
I have a WordPress web site and the site links was working good. For the last two days, suddenly found web site links redirect to the home page not the target link page. I checked the links code it's okay. I inspect links in the browser and I found this code changed for all links like this :
اتصل بنا
This means the right link code in ohref property and the alternative link code in href so all links open the main page for domain in href property.
What is the solution and what caused this problem?
href="" is where the link is directing. ohref="" is a custom attr that can only work with a javascript function. So unless you have an on click listener with javascript it has no function.If there is a javascript function it will overwrite the href="" with a preventdefault()
I have a ruby on rails app with a relative link on the page that has a wildcard subdomain.
For example:
https://username.mydomain.com with a relative link on an a tag:
/checkout
The checkout url should then bring the user to this page:
https://checkout.mydomain.com/username/buy
I have it going to the right visual display and the request parameters read the proper url, however, the url in the browser is listed as
https://username.mydomain.com/checkout
Is there a way to update the url when a user clicks the relative link. It appears it works only some of the time and I have tried turning off turbolinks by putting data-no-turbolinks in the body tag.
This one has got me stumped, I have a:
<%= link_to 'Login', users_path %>
That generates the html:
Login
And when I click on it, I don't get a response back from the Server. The address bar shows the correct url, http://localhost:3000/users, but nothing happens. When I click the address bar and hit enter, I get a response and I am directed to the users page.
In my routes.rb, the users entry is simply: resources :users
It also looks like it puts localhost:3000/#/users into the address bar and Chrome removes the #, could that be the cause and why is it putting the hash in there?
I ran Fiddler to see if the http request was being sent and sure enough, both sent to the server.
Can anyone explain this phenomenon? All my links are behaving this way, any help would be appreciated!
Found the answer here: Jquery Mobile all links ignore data-role="none"
You have to use either rel="external" or data-ajax="false".
Are you using devise or some other user-management-tool? Then there might be no root to /users.
You can run the following command to see, which routes are available:
rake routes
If you are using devise, try the following URL to find out, if it works:
http://localhost:3000/users/sign_in
If I want to make a DELETE link in rails, I write the following code (in this example case to delete a user session in Devise):
<%= link_to('Logout', destroy_user_session_path, :method => :delete) %>
That will turn into the following HTML:
<a rel="nofollow" data-method="delete" href="/users/sign_out">Logout</a>
Works great, except I can't simply put that HTML into a static HTML page. It will simply do a GET request. I assume Rails includes some standard Javascript to turn the above link to one that actually does a DELETE request. So what's the proper way to have a link on a static HTML page to a Rails resource that does a DELETE action? Should I find and grab that Javascript Rails includes in all webpages that does this? Is there a better way?
You can't send a DELETE request with an anchor link, unfortunately - a traditional anchor link will only send a GET request. Actually, you can't really send a true DELETE request at all. If you want to make a delete link, without javascript, the solution is fairly easy. Check out 2.4 How do forms with PUT or DELETE methods work? in the official documentation. Basically, you can simply create a form that submits to the url of your resource, with a method of delete. It's pretty simple, and you don't need to rely on javascript to get the job done. Hope this helps, good luck.
Rails uses JavaScript to handle delete links.
It creates a invisible form, and submits it when you click a link that has a data-method attribute of "delete"
Have a look at handleMethod in https://github.com/rails/jquery-ujs/blob/master/src/rails.js
Maybe your delete links in your static pages will just work when you include rails.js (if you are using jQuery).
If not, you can build a form as it is done in handleMethod on your own.
Since some of my colleagues are working on a native app where the user may not have the JavaScript enabled on their browsers, in such cases the delete link won't work and we would get the show page instead of delete....So if you are unsure whether the user may or or may not have the JS enabled on its browser, you can always generate a route with GET or POST method to the delete action of your controller...This approach would work for the static HTML pages also..
My Ruby on Rails web application has standard authentication. As the user logs in from the index page, I decided to model the index page as the "new" action of the "user_sessions" resource.
I decided to make the login form hidden using css, so that it could be made visible in a javascript launched modal dialog box.
The problem is now what do I do when the user has javascript turned off? Where do I send them to login?
I considered hiding the login form from javascript instead, so if javascript was turned off, the form would remain visible. Problem with this is that when the page is loading, the form will briefly appear before vanishing.
I wouldn't go that way. Build a normal index page, and link to the login form. Then with ujs, set the link as remote (so it's managed asynchronously) and register its handler to show the resulting form in a popup.
(in the view)
link_to new_user_session_path, :remote => true, :class => "possibly-modal-dialog"
(in some js or coffee file)
$(document).on "click", "a.possibly-modal-dialog", (event) ->
event.preventDefault
# to whatever needed to show the dialog.
This way, a user without javascript will see the normal link, and a user with javascript will just trigger the modal dialog.
Do you really need users with turned off javascript? Make notification for them on the home page:
<noscript>
<p><font color="red" size="3"><b>Javascript is turned off. <br/>
You need to change your browser settings.</b></font>
</noscript>