I'm in the process of creating a rails API for scheduling appointments. I'm worrying about making a generic app version first, and then I'm going to make it in to an API, as I havn't done that before.
I've been generating 4-5 scaffolds (rails generate scaffold _____ title:string description: text)
THEN running rake dbmigrate.
When I go to view the file on my local host, while running my rails server I get this error: (unfortunately I can't post images yet with my rep)
No route matches [GET] "/c4cc2"
Rails.root: /Users/Jack/Desktop/Project/CareCloudAttempt2/C4CC2
Application Trace | Framework Trace | Full Trace
Routes
Routes match in priority from top to bottom
Helper HTTP Verb Path Controller#Action
Path / Url
end_times_path GET /end_times(.:format) end_times#index
POST /end_times(.:format) end_times#create
new_end_time_path GET /end_times/new(.:format) end_times#new
edit_end_time_path GET /end_times/:id/edit(.:format) end_times#edit
end_time_path GET /end_times/:id(.:format) end_times#show
PATCH /end_times/:id(.:format) end_times#update
PUT /end_times/:id(.:format) end_times#update
DELETE /end_times/:id(.:format) end_times#destroy
start_times_path GET /start_times(.:format) start_times#index
POST /start_times(.:format) start_times#create
I've also tried entering the name of the routes after my URL
Here are my routes:
```
Rails.application.routes.draw do
resources :end_times
resources :start_times
resources :comments
resources :last_names
resources :first_names
end
```
I was wondering if maybe I needed to run rake db:migrate after each time I scaffold, over if it was another issue.
Thanks!
Migrating after couple of scaffolds is fine, no need to worry there.
What is c4cc2 supposed to be there? Rails looks for resource with that name in routes but isn't finding any. What are you trying to do with that?
This is not necessary you have run rake db:migrate after every scaffold, but you should run rake db:migrate before perform anything with rails server. If you have pending migration you may not browse your application.
But there is no problem with running rake db:migrate after every scaffold.
Related
I can't catch where a problem is.
I run on server
rails generate scaffold Place name:string lat:numeric lng:numeric
Next, I run
rake db:migrate
So, I try to create new Place on web browser and go to
/places/new
But receive:
ActionController::RoutingError (No route matches [GET] "/place/new"):
I confused because everything works fine on my local machine. What's wrong with me?
btw, routes.rb looks like:
Rails.application.routes.draw do
resources :places
end
You're saying you're navigating to places/new, but the log entry you've included shows that you're actually trying to navigate to place/new, which is not a valid route in this case. Use the plural for the resource.
numeric is not a datatype. You have to use float or integer for lat/long instead of numeric.
Corrected command:
rails generate scaffold Place name:string lat:integer lng:integer
I'm upgrading a very old rails application step by step. At the moment I am stuck at Rails 3.1. I did all the relevant steps for upgrading. For now I don't want to use assets so I disabled it in config/application.rb.
As soon as a change the rails version in my Gemfile from 3.0.20 to 3.1.12 I get a no-route-matches error. I also changed all upgrading steps back to 3.0 to see which part causes the error but it happens only when I change the line in the Gemfile.
My routes.rb:
Wawi::Application.routes.draw do
match ":controller(/:action(/:id(.:format)))"
end
Please tell me if you need more code.
rake routes:
/:controller(/:action(/:id(.:format)))
(and a warning: circular argument reference)
Maybe another useful hint: The action is part of the Application Controller.
are you calling Object#to_i on your object inside your url helper? may be the object is nil and nil.to_i is always 0. And also note, rails primary id starts from 1.
So you should give a try with running rake routes:
ruby bundle exec rake routes
After running that command you should see your url list that are available based on your route file.
Thanks to a colleague I found the solution:
In application_controller.rb session :session_key => '...' had to be changed to Rails.application.config.session_options[:key] = '...'.
How can I get the list of routes programatically in a rails 2 project. In a Rails 3 project,
Rails.application.routes.routes did what I wanted. But when I try this on a Rails 2 web site. It fails with the message No application method defined on Rails object.
you can look at the code for rake routes tasks most probably under
/gems/rails/2.3.x/lib/tasks/routes.rake for Rails 2.
ActionController::Routing::Routes.routes
look at the rake task in more detail to get a better Idea
you can try,
rake routes
this gives all the routes
UPDATE:
or on Rails 3+
bundle exec rake routes
After adding three custom member routes, everything works fine in the development and production environments, but fails in the testing environment.
In config/routes.rb, our custom member routes are copy, download and abort:
resources :kw_researches do
member do
get 'copy'
get 'download'
put 'abort'
end
end
Running rake routes shows the member routes are all fine and dandy (not a big surprise, as they actually work in production and development):
$ rake routes
copy_kw_research GET /kw_researches/:id/copy(.:format) kw_researches#copy
download_kw_research GET /kw_researches/:id/download(.:format) kw_researches#download
abort_kw_research PUT /kw_researches/:id/abort(.:format) kw_researches#abort
kw_researches GET /kw_researches(.:format) kw_researches#index
POST /kw_researches(.:format) kw_researches#create
new_kw_research GET /kw_researches/new(.:format) kw_researches#new
edit_kw_research GET /kw_researches/:id/edit(.:format) kw_researches#edit
kw_research GET /kw_researches/:id(.:format) kw_researches#show
PUT /kw_researches/:id(.:format) kw_researches#update
DELETE /kw_researches/:id(.:format) kw_researches#destroy
But the tests in both ./spec/views/kw_researches/index.html.erb_spec.rb and ./spec/integration/kw_research_index_page_spec.rb fail with errors such as the following:
10) KwResearch index page KwResearch has all relevant actions
Failure/Error: visit kw_researches_path
ActionView::Template::Error:
undefined method `copy_kw_research_path' for #<#<Class:0x007faab8c9a238>:0x007faab717fd40>
Why is copy_kw_research_path not available, while its good (standard helper) friend edit_kw_research_path is? Thanks...
When we returned to the problem two weeks later, it just disappeared: It would appear that restarting both the rails server (thin) and guard solved it.
rake routes is very slow (30s in my computer) but I need it for routing spec.
So, is there a way to get all routes like rake routes? (or how rake routes works?)
I use Rails 3 and all I have seen is for Rails 3, and I found nothing I can use in the rails doc.
Rails.application.routes.routes.to_a
.to_a is optional, it just converts it to an array.
(I found this line in railties/lib/rails/tasks/routes.rake)
I use it like :
routes[10].defaults => {:action=>"edit", :controller=>"polls"}
Edit : You can find the (quite hacky) way I do my routing specs here : https://gist.github.com/52ac6d848ce0d9fd52ac
If you're using RSpec, you can use routing specs in your tests.
Another option is the rake shell; I love it.