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

Routing error: uninitialized constant Api::V1::Category #5

Open
lifeBalance opened this issue Nov 19, 2015 · 15 comments
Open

Routing error: uninitialized constant Api::V1::Category #5

lifeBalance opened this issue Nov 19, 2015 · 15 comments

Comments

@lifeBalance
Copy link

Hi, I'm in page 94 following along, and running the first curl throws the error mentioned in the title.
This is my wikicat project in case you wanted to check.
Rails 4.2.4
Ruby 2.2.2p95

@hiromipaw
Copy link
Owner

Hey,
did you defined new routes without restarting the server?

@lifeBalance
Copy link
Author

I wouldn't open an issue without having put a fair amount of fight )) But yeah, I restarted the router like probably a dozen times, and went over the code (it wasn't much, really) quite a few times.

@hiromipaw
Copy link
Owner

Could you use the following syntax in your routes?

  get '/category/:category', :to => 'category#show'

Also please respect the spaces. I know it doesn't matter but it makes reading the code easier and everything more consistent for larger projects.
Then you will have the respond_to error. This is because of the updates to Rails and Rails-api. If you downgrade the gems version as in my original repo you will be fine.

Thanks for reaching out!!

Silvia

@lifeBalance
Copy link
Author

Thanks Silvia, but that syntax is allowed in hashes with symbol keys since version 1.9.. Also, in your original repo, none of the gems in your Gemfile (except sdoc) include a version, only Rails does.
One of the things I've noticed in your repo is that your ApplicationController inherits from ActionController::Base whereas mine inherits from ActionController::API. Also, you have a views/layout folder with application.html.erb layout in it. It looks like you have generated your app with rails new instead of rails-api new.

@hiromipaw
Copy link
Owner

Hey there!
Yes the syntax is allowed, but something in the way you write it gets it messed. I cloned your repository and did the change suggested and it works. I will send you a PR so you can try it out.
Also there are a few little differences between rails and rails-api, but these shouldn't impact at all the way you build the API at this stage.
To check the version I used in my repository check the Gemfile.lock file.

@lifeBalance
Copy link
Author

So you say my project works on your machine with the edit on routes? I still get the same error. What's your ruby version?

@hiromipaw
Copy link
Owner

$ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]

@lifeBalance
Copy link
Author

Oh boy, I deleted the project folder, cloned my repo, bundle update(This time I change Rails in the Gemfile to the version you use), and now am getting NoMethodError undefined methodraise_in_transactional_callbacks=' for #Class:0x007fba2b575f98`
Does that make any sense?

@hiromipaw
Copy link
Owner

I sent you a PR regarding the routes. Also please do not run bundle update, use the version from my repo by looking at the Gemfile.lock.

@lifeBalance
Copy link
Author

Yeah, I merged your PR. Now, I've copy/paste your Gemfile.lock, run bundle, and same weird NoMethodError undefined methodraise_in_transactional_callbacks.
Do you think does have anything to do with dropping the db? Before, when I started with your book, I tried the dumps, before I realize one of them was > 10 gb 😔 , and had cut it out in the middle when I was running out of space in my HDD and DROP the db.
Then I took the seed file solution, and seeded it, of course.

@hiromipaw
Copy link
Owner

It is better to use the information in ghe Gemfile.lock to specify a specific version of a gem in your Gemfile.
If you have dropped the db, you have to run rake db:setup.
Also I have sent a second PR, please check it.

@lifeBalance
Copy link
Author

Wow, girl you are tough, I don't know where are you based but here in Moscow(I'm spanish though) is past 5, so I'm gonna wrap up. Thanks for your help.

@lifeBalance
Copy link
Author

Hey Silvia, I got it working. It was indeed a silly eye-straining error on my side, that slipped our defenses:

 get 'category/:category', :to => 'category/#show'

See that slash before the #show action? 🙀

Anyways, I ended up starting over here wicked where I used the most up to date versions of all gems, hopefully I won't find problems along the line.

Indeed I hit the respond_to error you mentioned, because from Rails 4.2.*, class-level methods such as respond_to have been moved to the responders gem, so instead of reverting to an older Rails version, I just added it to my Gemfile.

@hiromipaw
Copy link
Owner

Hey @Bifork,
Thanks for your comments, some of the errors are related to old version of Rails. I am sorry about those, but I wrote the book 2 years ago now. I am planning on releasing an update, hopefully in the spring.

@ghost
Copy link

ghost commented Dec 12, 2016

Thank @hiromipaw for your reply, Silvia.

Though I cannot hope for a big revamp in your spring release. But I do wish you could take time to expand your wonderful topics to greater detail. Right now, your book seems to be friendly to really experienced developers.

I wish you could include the user model and authentication solution from the start. Then a RESTful resources owned by a user and conversations/comments about a RESTful resource object between users. Besides the relationship/association between models, if you can include a transaction like payment or ownership transfer, it would be all too great.

I can imagine you are incredibly busy, especially for a girl who pursues highest academic degree besides cutting-edge programming skills. But I believe, if you spend time to write an awesome popular book, you can make money while you're sleeping or playing on your beautiful beaches.

I wish I could be a great author after becoming very skilled. But I'm not experienced yet and still slowly researching. A foggy world to me right now.

Muchas gracias:)

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