I have been building a small app to import a cv from linkedin.
Displaying the information is working out perfect, but saving it to
the database is turning out to be a challenge.
The full source code is at https://github.com/brunoamaral/lwork and
the source code of the import function is as follows:
def importcv
@user = User.find_by_username(params[:username])
client = LinkedIn::Client.new(@linkedin_apikey, @linkedin_secret)
t = current_user.authentications.find_by_provider('linked_in')
client.authorize_from_access(t.token, t.secret)
@cv = client.profile(:fields =>
[:headline, :first_name, :last_name, :educations, :positions])
@user.positions << @cv.positions
@user.positions.save
end
When running it, I get the message:
undefined method `match' for LinkedIn::Position::Resource:Class
The model adds the following to users:
has_many :positions, :class_name => LinkedIn::Position::Resource
What bugs me more is that I don't even know where to start looking for
an answer to this, so any hints on where to search and what to look
for are welcome.
match is a method of String, so I wonder whether it is getting called
on the above type instead of a string. The error should show a stack
trace which should show you which line of your code it is failing on.
Post the complete error and trace if you cannot work it out.
Colin
The error message mentions line 44:
@user.positions << @cv.positions
@user.positions.save
the full output is here: http://dl.dropbox.com/u/109441/errormessagerails.html
@cv.positions is an array, so from what you're telling me it should
not use "match" as a method.
Please don't top post, it makes it difficult to follow the thread.
Insert your reply at appropriate points in previous message. Thanks.
The error message mentions line 44:
@user.positions << @cv.positions
@user.positions.save
the full output is here: http://dl.dropbox.com/u/109441/errormessagerails.html
Don't you get a full error trace, in the server terminal window or
log/development.log?
@cv.positions is an array, so from what you're telling me it should
not use "match" as a method.
You realise that, if user.positions is also an array that
@user.positions << @cv.positions
will attempt to add the whole array @cv.positions as a single element
on the end of @user.positions. Not append the contents of
@cv.positions as multiple new elements. Are you sure you do not want
@user.positions += @cv.positions
I don't know what @user.positions is of course so I may be
misinterpreting something.
Colin
Please don't top post, it makes it difficult to follow the thread.
Insert your reply at appropriate points in previous message. Thanks.
> The error message mentions line 44:
> @user.positions << @cv.positions
> @user.positions.save
> the full output is here:http://dl.dropbox.com/u/109441/errormessagerails.html
Don't you get a full error trace, in the server terminal window or
log/development.log?
I do have a full trace at http://pastie.org/1825323
and the server log is http://pastie.org/1825336
You realise that, if user.positions is also an array that
@user.positions << @cv.positions
will attempt to add the whole array @cv.positions as a single element
on the end of @user.positions. Not append the contents of
@cv.positions as multiple new elements. Are you sure you do not want
@user.positions += @cv.positions
cv.positions is the information the user has in the experience bit of
their LinkedIn profile.
composed of user_id: integer, company: string, end_month: string,
end_year: string, start_month: string, start_year: string
Using += resulted in the exact same error message, which is strange I
was hoping to at least get more information from rails. Maybe it means
the problem is not the line 44 but something else.
Do you mean each member of the array (or association) positions is one
of those. I am a bit confused by the line @user.positions.save. Can
you do save on an array? Or is positions a single record, in which
case it should be called position, singular.
Is there a Position model then, with cv has_many positions ?
What happens if you do something like
@cv.postions.each do |position|
@user.positions << position
end
Can you post the model definitions? Not all the methods just the
definitions and associations and so on.
Have you used ruby-debug or a similar to technique to break in and
check that all the variables are as you expect.
Colin
adding ruby-debug froze the import page, but I will keep trying to
check the variables as you said.
about the model, the source code is in the github project
https://github.com/brunoamaral/lwork/blob/master/app/models/user.rb
class User < ActiveRecord::Base
has_many :authentications
has_many :positions, :class_name => LinkedIn::Position::Resource
This looks wrong, since :class_name is supposed to be a string and
LinkedIn::Position::Resource isn't
Fred
However, not using it only returns
Position(#2174910600) expected, got
LinkedIn::Position::Resource(#2173297260)
I am thinking about taking a different approach, since I can't figure
out how to save the information I need in one go the other option is
to try to build an import form.