Ruby on rails NoMethodError(未定义的方法'search=';for#<;Profile:0x000000016d1fb8>;)处于生产模式,但不处于开发模式
我的web应用程序在开发模式下工作得很好,但在生产模式下我甚至无法登录。一旦我登录,就会出现以下错误:Ruby on rails NoMethodError(未定义的方法'search=';for#<;Profile:0x000000016d1fb8>;)处于生产模式,但不处于开发模式,ruby-on-rails,postgresql,sqlite,heroku,Ruby On Rails,Postgresql,Sqlite,Heroku,我的web应用程序在开发模式下工作得很好,但在生产模式下我甚至无法登录。一旦我登录,就会出现以下错误: NoMethodError (undefined method `search=' for #<Profile:0x000000016d1fb8>). NoMethodError(未定义的方法'search='for#)。 如果我注册并创建个人资料,则会出现相同的错误。我如何解决这个问题?我正在aws cloud 9环境中使用ruby on rails,并试图部署到herok
NoMethodError (undefined method `search=' for #<Profile:0x000000016d1fb8>).
NoMethodError(未定义的方法'search='for#)。
如果我注册并创建个人资料,则会出现相同的错误。我如何解决这个问题?我正在aws cloud 9环境中使用ruby on rails,并试图部署到heroku。我使用sqllite3进行开发,使用postgressql进行生产
这是我的profilescontroller.rb
class ProfilesController < ApplicationController
before_action :authenticate_user!
before_action :only_current_user
# GET to /users/:user_id/profile/new
def new
# Render blank profile details form
@profile = Profile.new
end
# POST to /users/:user_id/profile
def create
# Ensure that we have the user who is filling out form
@user = User.find( params[:user_id] )
# Create profile linked to this specific user
@profile = @user.build_profile( profile_params )
if @profile.save
flash[:success] = "Profile Created"
redirect_to user_path(id: params[:user_id] )
else
render action: :new
end
end
def edit
@user = User.find( params[:user_id] )
@profile=@user.profile
end
def update
@user = User.find( params[:user_id] )
@profile = @user.profile
if @profile.update_attributes(profile_params)
flash[:success] = "Profile Updated."
#redirect to their profile page
redirect_to root_path
else
render action: :edit
end
end
private
def profile_params
params.require(:profile).permit(:first_name, :last_name, :avatar, :age, :gender, :city, :collegeemail, :minimumage, :maximumage, :genderpreference, :collegepreference, :search)
end
def only_current_user
@user = User.find( params[:user_id] )
redirect_to(root_url) unless @user == current_user
end
end
class ProfilesController
听起来,配置文件的表格在生产中与开发中不一样。具体来说,search
列似乎缺失,导致Profile
没有用于search
的getter和setter
我假设您忘记在生产环境中运行迁移,这会将搜索列添加到配置文件模型的表中。听起来配置文件模型的表在生产环境中与开发环境中不一样。具体来说,search
列似乎缺失,导致Profile
没有用于search
的getter和setter
我假设您忘记在生产环境中运行迁移,这会将搜索
列添加到配置文件
模型的表中。当表中没有特定列时,就会出现上述错误。确保我们已经在产品上运行了迁移,或者只是查看schema.rb文件,然后在概要文件表中查找列“search”。如果表中没有特定列,则会出现上述错误。请确保我们已经在生产环境中运行了迁移,或者只是查看schema.rb文件,然后在概要文件表中查找“search”列。对于开发和生产环境,您有相同的代码吗?上面显示的问题表明,无法为Profile
的search
赋值。是的,我已经运行了所有迁移。对我来说,搜索总是在个人资料模型中。我刚刚重新进行了迁移,以确保迁移过程顺利进行。你知道还有什么不对劲吗?我也在使用websolr插件。这可能是我的错误的来源吗?您有相同的开发和生产代码吗?上面显示的问题表明,无法为Profile
的search
赋值。是的,我已经运行了所有迁移。对我来说,搜索总是在个人资料模型中。我刚刚重新进行了迁移,以确保迁移过程顺利进行。你知道还有什么不对劲吗?我也在使用websolr插件。这可能是我出错的原因吗?是的,这是一个迁移问题。谢谢@索尔德蒙德:那你为什么不接受我的回答呢?在我看来,我的观点是第一位的,也是更广泛的,因此投票;)是的,这是一个迁移问题。谢谢@索尔德蒙德:那你为什么不接受我的回答呢?在我看来,我的观点是第一位的,也是更广泛的,因此投票;)