I recently added image_url
and pin1
through pin4
fields to my blogs
table of my Rails app.
I added them to the schema:
create_table "blogs", force: :cascade do |t|
t.string "title"
t.string "teaser"
t.text "body"
t.boolean "published", default: false
t.datetime "published_at"
t.string "video_url"
t.bigint "spree_user_id", null: false
t.bigint "resource_id", null: false
t.string "slug"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "image_url"
t.string "pin1"
t.string "pin2"
t.string "pin3"
t.string "pin4"
t.index ["resource_id"], name: "index_blogs_on_resource_id"
t.index ["spree_user_id"], name: "index_blogs_on_spree_user_id"
I added them to the controller params:
def blog_params
params.require(:blog).permit(
:title,
:teaser,
:body,
:image,
:published,
:published_at,
:subcategory_ids,
:image_url,
:video_url,
:pin1,
:pin2,
:pin3,
:pin4,
:user_id,
:resource_id,
:slug
)
end
And to the form:
<%= form.label :image_url %>
<%= form.text_field :image_url, class: "form-control" %>
...
<%= form.label "Pinterest Pin Url 1" %>
<%= form.text_field :pin1, class: "form-control" %>
Everything works perfectly and they display on my localhost:
<% if @blog.pin1 %>
<%= image_tag @blog.pin1, class: "pin shadow-bottom", style: "display: inline-block" %>
<% end %>
But on Heroku the values don't save. I get no errors, server log or otherwise. I did heroku run rake db:migrate
with no errors.
Can anyone see what's going wrong?
You can inspect your database a bit with psql
:
heroku pg:psql
Once at the SQL prompt, you can look at your table to see if the changes got applied:
\d blogs
One thing to note is that in production Rails will cache your database schema on application boot, so if you ran your migrations but haven't restarted your application since the migrations were run with rake db:migrate
, ActiveRecord would not have awareness of the new the fields. You can restart the application with heroku restart
and then check to see if that makes a difference.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments