The form_for method in devise spits out some HTML, but is there any way to edit that default HTML? So basically, I want the text boxes to have HTML placeholders but by default they do not, and I can't seem to edit this HTML. Thanks.
Asked
Active
Viewed 1,045 times
0
-
2Is this what you are looking for? https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app – iltempo Nov 09 '12 at 01:25
-
1No, what he is looking for is this: https://github.com/plataformatec/devise#configuring-views . user1810958, you should definitely search for a gem's documentation first and only ask questions later. – Ashitaka Nov 09 '12 at 01:52
-
Ashitaka, this is a site dedicated to asking questions. Maybe I made a mistake coming to this website then. I've done enough research on my own. This does not answer my question. rails generate devise:views doesn't help me change how the form looks - there is no file inside any of these html.erb files that can change the HTML spit out by the form, something like a _form file. – user1810958 Nov 09 '12 at 04:28
-
@user1810958: Yes there is, actually. Please look at the files that that command generates. – Ryan Bigg Nov 09 '12 at 04:38
-
Ryan, I've checked all files it generates. Nothing there can change the HTML spit out by the form_for. Which file are you referring to? – user1810958 Nov 09 '12 at 05:12
1 Answers
0
You can customise the Devise's default views by copying the view files to your application view directory. There you can modify them as you want. When devise action render views, it first will look for your app/views/devise
directory. If it finds corresponding views there, it will render that. It will render it's default one otherwise.
To copy the views, run the following command:
rails g devise:views
This will create a new directory in app/views
named devise
. Suppose, you want to customise the new registration form. It resides in app/views/devise/registrations/new.html.erb
You can edit them in the way prefer. To add a placeholder
attribute, let's say for the email field, you need to edit the line:
<%= f.email_field :email %>
with
<%= f.email_field :email, :placeholder => 'Enter your email address' %>
You can add any custom attribute in this same way

HungryCoder
- 7,506
- 1
- 38
- 51
-
Thank you so much, this is exactly what I wanted. I didn't know you could do this directly from Rails. – user1810958 Nov 09 '12 at 16:11