我在heroku服务器上遇到了一些麻烦。没有在本地遇到这个问题:
2014-07-23T16:59:23.249055+00:00 app[web.1]: ActiveRecord::UnknownAttributeError (unknown attribute: authorname):
2014-07-23T16:59:23.249058+00:00 app[web.1]: app/controllers/chapters_controller.rb:5:in `create'
我的控制器:
class ChaptersController < ApplicationController
def create
@story = Story.find(params[:story_id])
@chapter = @story.chapters.create(chapter_params)
redirect_to story_path(@story)
end
def destroy
@story = Story.find(params[:story_id])
@chapter = @story.chapters.find(params[:id])
@chapter.destroy
redirect_to story_path(@story)
end
def upvote
@chapter = Chapter.find(params[:id])
@chapter.votes.create
redirect_to(:back)
end
private
def chapter_params
params.require(:chapter).permit(:round, :author, :authorname, :body)
end
end
我刚刚添加了authorname
rails g migration add_authorname_to_chapter authorname:string
我错过了什么?
编辑,添加架构信息: ActiveRecord :: Schema.define(版本:20140723154333)做
create_table "chapters", force: true do |t|
t.string "round"
t.string "author"
t.text "body"
t.integer "story_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "authorname"
end
答案 0 :(得分:6)
迁移后重新启动服务器将刷新架构缓存。
答案 1 :(得分:2)
对于重启不起作用的情况,我还可以通过转储模式解决此问题:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Matchit{
public static void main(String []args){
String str = "process_abc_pqr_client_123_Tree";
Pattern p = Pattern.compile("process_abc_pqr_client_(.*)|process_client_(.*)");
Matcher m = p.matcher("process_abc_pqr_client_123_Tree");
if (m.find( )) {
System.out.println("Found value: " + m.group(1) );
}
}
}