CHarris
CHarris

Reputation: 2793

ruby on rails button_to or ideally f.button

I'm working on a 'Log In' / 'Sign Up ' form, a project I've 'inherited' from someone else. My Rails isn't that advanced but I'm enjoying it, apart from frustrations of getting something tiny to work in about 10 hours.

When people want to log in, after entering their username and password, they click a 'Log in' button, which works fine:

<%= f.button :submit, I18n.t('sign_in.sign_in_button'), :class => 'btn btn-primary' %>

Now, how can I create a Sign Up button that directs the user to the 'Create account' page?

For example, this link works perfectly:

<%= link_to I18n.t('sign_in.sign_up'), new_user_registration_path %>

new_user_registration_path goes to the 'Create account' page. Is there nowhere I can stick new_user_registration_path within my button code?

I tried this too, put when clicked it just keeps refreshing the current page, rather than going to the 'Create Account' page:

<%= button_to I18n.t('sign_in.sign_up_button'), new_user_registration_path, :class => 'btn btn-warning' %>

Upvotes: 1

Views: 1933

Answers (1)

Adam Tanner
Adam Tanner

Reputation: 927

It looks like you're using Bootstrap. This is the perfect use case for a link as you have, but styled as a button. Try: <%= link_to I18n.t('sign_in.sign_up'), new_user_registration_path, :class => "btn btn-warning" %>

Upvotes: 1

Related Questions