Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returns empty object #87

Closed
TheRPunkt opened this issue Sep 15, 2017 · 5 comments
Closed

Returns empty object #87

TheRPunkt opened this issue Sep 15, 2017 · 5 comments

Comments

@TheRPunkt
Copy link

Hello everybody,
I'm new to this gem and wanted to build it into my app. So firstly, I started just by creating a shortened url. I tried the following:
Shortener::ShortenedUrl.generate("https://github.com/jpmcgrath/shortener")
However the first SQL Statement instantly rollbacks and I get a an empty object back:

Shortener::ShortenedUrl Load (0.4ms)  SELECT  "shortened_urls".* FROM "shortened_urls" WHERE "shortened_urls"."url" = ? ORDER BY "shortened_urls"."id" ASC LIMIT ? [["url","https://github.com/jpmcgrath/shortener"], ["LIMIT", 1]]
   (0.1ms)  begin transaction
   (0.1ms)  rollback transaction
=> #<Shortener::ShortenedUrl:0x007fc34c4b6f88 id: nil, owner_id: nil, owner_type: nil, url: "https://github.com/jpmcgrath/shortener", unique_key: nil, use_count: 0, expires_at: nil, created_at: nil, updated_at: nil>

Maybe someone can help me on that.. :/

@jpmcgrath
Copy link
Owner

jpmcgrath commented Oct 20, 2017

Hi @TheRPunkt, what is the result when you try the bang (!) version of the generate method? i.e. Shortener::ShortenedUrl.generate!("https://github.com/jpmcgrath/shortener"). I expect there will be an exception raised that will point us in the right direction.

@TheRPunkt
Copy link
Author

Hi, thanks for your help :) When trying out the method you pointed out, active records rollbacks the transaction and returns an empty shortened url object. When trying out object.errors.full_messages there is the message "Owner must exists". However I did not have setup the owner possibility you mentioned in the readme file... Do you have an idea?

@jpmcgrath
Copy link
Owner

What version of Rails are you using? It might be because Rails5 has introduced an implicit validates_presence_of for belongs_to associations. If you are on Rails5, i have yet to address this, but some others have done some good work on creating a Rails5 branch that can be used in the interim.

@jpmcgrath
Copy link
Owner

#83

@TheRPunkt
Copy link
Author

I'm working with version 5.0 of rails and already saw the issues about it. Additionally, I already tried multiple branches which should be updated but did not work out. However, this one one is working just fine. Thanks for your help, could've found that myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants