Ruby on rails 类型错误:can';t cast LinkedIn::Mash-to-text错误
我正在尝试在rails应用程序中保存调用Linkedin API的数据,但当它转到保存时,我收到错误:Ruby on rails 类型错误:can';t cast LinkedIn::Mash-to-text错误,ruby-on-rails,ruby,api,linkedin,Ruby On Rails,Ruby,Api,Linkedin,我正在尝试在rails应用程序中保存调用Linkedin API的数据,但当它转到保存时,我收到错误: TypeError: can't cast LinkedIn::Mash to text 我也不希望用户编辑信息,因此我在新控制器中设置信息,如下所示: def new @client = LinkedIn::Client.new @client.authorize_from_access(current_user.consumer_token, current_user.consu
TypeError: can't cast LinkedIn::Mash to text
我也不希望用户编辑信息,因此我在新控制器中设置信息,如下所示:
def new
@client = LinkedIn::Client.new
@client.authorize_from_access(current_user.consumer_token, current_user.consumer_secret)
@resume = Resume.new do |u|
u.location = current_user.location
u.picture_url = current_user.image_url
u.summary = @client.profile(:fields => %w(summary))
u.work_experience = @client.profile(:fields => %w(positions))
u.education = @client.profile(:fields => %w(educations))
u.user = current_user
end
@resume.save!
if @resume.save
flash[:succes] = "Resume Saved!"
redirect_to resumes_path
else
flash[:error] = "Resume did not save."
redirect_to resumes_path
end
end
这被认为是坏习惯吗?我应该在创建控制器中设置保存吗?打字错误呢?我觉得,由于我直接从API保存信息,因此无法将其保存为普通测试。这就是您的
config/routes.rb
的外观:
resources :resumes
这是控制器中的#create
方法
def create
@resume = Resume.new(params[:resume]) # if you are on rails 4 then you have to use strong params
if @resume.save
flash[:succes] = "Resume Saved!"
redirect_to resumes_path
else
flash[:error] = "Resume did not save."
redirect_to resumes_path
end
end
#create
方法自然就是一篇文章。此资源对于理解路线非常有帮助。至于您关于mash的问题,我认为这里已经回答了。您肯定应该在create controller中有save位。为了回答第二个问题,我很好奇它发生在哪一行。谢谢@Sean,在方法结束后,要在控制器中的create方法中发布什么方法?我正想把你引向,但那是不对的。谢谢!