Very green question here. I built a simple blog following the instructions here http://guides.rubyonrails.org/getting_started.html
How can I add another string variable to the post object?
Once I have a new variable, how do I create new posts in html.erb files? The code below gives me a NoMethodError exception for the 'email' method. How do I make this code run without an error?
btw - what is convention on stackoverflow for followup questions?
<h2>Add a post:</h2>
<%= form_for([@post, @post.actions.build]) do |f| %>
<div class="field">
<%= f.label :number_performed %><br />
<%= f.text_field :number %>
</div>
<div class="field">
<%= f.label :your_email %><br />
<%= f.text_field :email %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
At the very least to get the minimum functionality, you must add another column to your post table.
See here on how to add a column programitcally:
http://api.rubyonrails.org/classes/ActiveRecord/Migration.html
OR you can run the rails generate migration command like so:
rails generate migration AddColumnNameToPost column_name:string
No matter what route you go down, make sure you run the following to apply those migrations to your database:
rake db:migrate
From there you can access:
@post = Post.new
@post.column_name = "value"
#etc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With