i have the below code, and i just want to link my button to the next view
<button type="submit" class="login-button"><link_to home_page.html.erb></link_to>
<i class="fa fa-chevron-right"></i></button>
how can i fix this
i have the below code, and i just want to link my button to the next view
<button type="submit" class="login-button"><link_to home_page.html.erb></link_to>
<i class="fa fa-chevron-right"></i></button>
how can i fix this
I suppose you have form_tag or form_for somewhere outside your button.
You could do it totally the Rails way like
<%= submit_tag("submit") %>
or if you prefer a link
<%= link_to 'submit', your_path, your_options %>
or a button
<%= button_to 'subimit, your_path, your_options %>
just have a look rails guides and you will find plenty of examples
=> link_to generates a <a>
tag, which is not input type="submit"
.Use button_to, which generates a form with a input type="submit"
button to the link.
Assuming path of home_page.html.erb is homepage_path
(replace it with your path.)
<%= button_to home_page_path,class: "login-button", method: :get do%>
<i class="fa fa-chevron-right"></i>
<% end %>
Alternatively you can use like this:-
<%= button_to "<i class="fa fa-chevron-right"></i>".html_safe, homepage_path, class: "login-button", method: :get %>
I'm not sure to have understood, but if you need to link to another page you don't need a button, you need a link.
You can add a simple link to that url (not the page, but the route to that page) and style it as a button with css if you want to make it look as you like.
If you need to submit and elaborate some stuff calling a method from your controller, it depends:
1.If your controller is a simple controller you can manage it with a redirect_to at the end of your method
def method
# your elaboration
redirect_to :your_route
end
2.If it is an API controller and you call it from a javascript function, you can add to your callback a window.location.href to your route
success: (data) => {
// your elaboration
window.location.href = "path/to/your/page"
}