-4

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

user6118473
  • 13
  • 2
  • 6

3 Answers3

0

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

sissy
  • 2,908
  • 2
  • 28
  • 54
0

=> 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 %>
Anand
  • 6,457
  • 3
  • 12
  • 26
  • Still using the older ruby syntax for `Hash`: `:class => "login-button"` ? – Jagdeep Singh Jul 05 '18 at 11:19
  • 1
    @JagdeepSingh Thanks for point me out, fat arrow syntax should not be used, but still it works, well i'll update the answer :) – Anand Jul 05 '18 at 11:25
  • @Gabbar: what do you mean, "should not be used"? It's not like this form is deprecated or anything. JFYI, the term here is "hashrocket", not "fat arrow" – Sergio Tulentsev Jul 05 '18 at 14:19
  • So far as I know it's old syntax and it's not good practice to use that has rocket syntax . Am i right? – Anand Jul 05 '18 at 16:26
0

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"
}
Pietro Allievi
  • 386
  • 6
  • 14