I am fairly new to ruby on rails, and am experimenting with the structure and functionality of RoR and want to know how to create a simple reload link using RoR instead of the static HTML way
Asked
Active
Viewed 1.2k times
6
-
You want reload the current page or redirect it to other? – techvineet Sep 12 '13 at 09:22
-
reload the current page sorry – Stacker-flow Sep 12 '13 at 09:22
-
it will be good if you can add it in the javascript rather than in your rails code. in rails you can do redirect_to :back – Sabyasachi Ghosh Sep 12 '13 at 09:23
-
Use `link_to(params)` – pierallard Sep 12 '13 at 09:23
-
I have a list of URL's that RoR fires off and presents the response code from the given URL's so I can quickly present environments that are up or down etc – Stacker-flow Sep 12 '13 at 09:27
-
Possible duplicate of http://stackoverflow.com/questions/7465259/ruby-on-rails-reload-current-page – sjain Sep 12 '13 at 09:34
4 Answers
14
link_to "reload", url_for(params)

bubblez
- 814
- 1
- 8
- 14
-
1An attacker can send someone else a link and that way decide the arguments for `url_for`. That can probably be used to make the "reload" link do stuff it shouldn't. – Rune Schjellerup Philosof Jun 15 '17 at 14:03
3
If you just do an empty string for the url:
<%= link_to "Refresh", "" %>
, that will link back to current page. Assuming you want to clear the params.
If you want a refresh with the params then do as @bubblez answered:
<%= link_to "Refresh", url_for(params) %>
.

RebelOfBabylon
- 658
- 5
- 12
0
It is better to keep it doing with Javascript. Rails could help you in case you want to redirect.

techvineet
- 5,041
- 2
- 30
- 28
0
I'm not entirely sure why you want to just reload the page. (Probably need a bit more context) but you could just generate a link on the page that will reload it like this:
<%= link_to "reload", root_path %>
That will just output a link to the root_path, you can redirect back to whatever page you are currently on by changing the second parameter in the link_to helper. For list of routes, run "rake routes".

derekyau
- 2,936
- 1
- 15
- 14
-
I have a list of URL's that RoR fires off and presents the response code from the given URL's so I can quickly present environments that are up or down etc – Stacker-flow Sep 12 '13 at 09:27
-
-
Well I am using Net:HTTP to go to the URL I have defined and present back the response code next to the URL – Stacker-flow Sep 12 '13 at 09:30
-
Okay, starting to make more sense.. So you want the page to just reload and essentially refresh all of these statuses? – derekyau Sep 12 '13 at 09:32
-
1If thats the case, I would go for a simple link_to call with a path back to your current page, or simply do it through JS – derekyau Sep 12 '13 at 09:33
-
What is your current controller and controller action that renders this view? – derekyau Sep 12 '13 at 09:35