I made a blogpost with two entries (title, content) like this
rails generate scaffold Post title:string content:text
This works, but
-
What if I want to add a new input area later? Ex.
authorfield or something. Where do I add more fields to my Post scaffold? -
I made a stylesheet
style.cssinside my public directory. Its just sitting there. How do I link it to my file inapp/views/post/new.html.erbfor example? -
Where can I learn all the tweaks for scaffolding a specific field? Ex. I want the
titleinput field to not contain special characters (ex.@#$%) or not be more than certain length.
I am using windows and rails 3.2.8.
A 3 in 1 question 🙂
1st answer
As others said you need to modify your table to have the new fields, and this can be easily done with a migration:
But you also need to modify your views, because it won’t contain the new field. The corresponding views are in
app/views/posts(look foredit.html.erbandnew.html.erb).Of course you’ll need to run your migration on your database:
2nd answer
You can add your stylesheets to your views in
app/views/postsbut I recommend you to use layouts for your application, The layouts sit in theapp/views/layouts. You can simply create anapplication.html.erbin your layouts directory and put your CSS includes there.The yield block will contain the actual output of your views, so you should remove these parts from the existing views.
3rd answer
If you want to control the accepted characters for a certain field, you could do it in a validation in your model.