I'm getting this error:
uninitialized constant OpenidsController
I can't figure out why. I'm following this guide: http://www.danwebb.net/2007/2/27/the-no-shit-guide-to-supporting-openid-in-your-applications
I used the following command to generate the controller:
script/generate controller Openid new create complete
And I have put the following line in my routes file as the guide says to do:
map.resource :openid, :member => { :complete => :get }
Any ideas? I'm new to RoR so hopefully this is easy for someone else.
You can either change your route to this
map.resource :openid, :member => { :complete => :get }, :controller => 'openid'
or rename your controller class to OpenidsController.
One thing to take note of is that blog post is nearly 3 years old - you might want to consider other articles as well.
You might find this OpenID example helpful, though it's also a little dated at this point.
Related
I have a legacy Rails app which started life in Rails 1.2.
It has been converted through to Rails 5.0 over the years
The routes.rb file contains only two lines of 'wildcard routes' as follows
match ':controller(/:action(/:id))',:constraints => {:controller => /admin\/[^\/]+/}, :via => :all
match '/:controller(/:action(/:id))(.:format)', :via => :all
Links within the application are codedas in the following example:
<%= link_to('Marital Status', {:controller => 'marital_status', :action => 'list'}) %>
It appears that this sort of route is deprecated and will be removed in Rails 5.2
My question is how can I convert the routes to something that is acceptable to Rails 5.2.
Bear in mind that the application has about 150 controllers with a corresponding large number of actions.
I am in a similar boat and for the time being I made a rake task to generate all of the routes and write them to the routes.rb file.
Using a little ruby meta-programming its pretty straight forward to find all the methods available to a class <controller>.instance_methods then filter out all of the built in rails methods + those inherited from the application controller.
update:
I used a rake task to generate routes and put the following code in the bottom of the routes file to log when a route was not found in production:
match '/:controller(/:action(/:id))(.:format)', :via => :all, :to => proc { |env|
route = env["action_dispatch.request.path_parameters"]
Rails.logger.error("******************************************************************************************************")
Rails.logger.error("ROUTE NOT FOUND. USING WILDCARD ROUTE. REQUIRED ROUTE IS:>")
Rails.logger.error("#{env['REQUEST_METHOD'].downcase} #{route[:controller]}/#{route[:action]} => #{route[:controller]}##{route[:action]}")
Rails.logger.error("******************************************************************************************************")
controller = eval("#{route[:controller].camelize}Controller")
action = route[:action]
controller.action(action).call(env)}
Because match method has been deprecated, use get for GET and post for POST.
eg. get '/list', to: 'marital_status#list'
I'm migrating an application from Rails 2.3.5 to Rails 3.2.8.
I have this route from the Rails 2 app that is giving me headaches:
map.resources :soumission_vt,
:path_prefix => "/soumission/VT/:page_id", :as => 'police/:action/:id',
:requirements => {:page_id => /\S+/}
wich generates the following:
soumission_vt_index GET /soumission/VT/:page_id/police/:action/:id(.:format) {:controller=>"soumission_vt"}
POST /soumission/VT/:page_id/police/:action/:id(.:format) {:controller=>"soumission_vt"}
new_soumission_vt GET /soumission/VT/:page_id/police/:action/:id/new(.:format) {:controller=>"soumission_vt"}
edit_soumission_vt GET /soumission/VT/:page_id/police/:action/:id/:id/edit(.:format) {:controller=>"soumission_vt"}
soumission_vt GET /soumission/VT/:page_id/police/:action/:id/:id(.:format) {:controller=>"soumission_vt"}
PUT /soumission/VT/:page_id/police/:action/:id/:id(.:format) {:controller=>"soumission_vt"}
DELETE /soumission/VT/:page_id/police/:action/:id/:id(.:format) {:controller=>"soumission_vt"}
I translated it this way in Rails 3:
scope '/soumission/VT/:page_id', :constraints => {:page_id => /\S+/} do
resources :soumission_vt, :as => 'police/:action/:id'
end
but I am getting an Invalid route name: 'police/:action/:id_index'...
So is there a way to reproduce those routes in Rails 3?
Thanks!
After one try, I succeeded to make it work with the following lines of code:
scope '/soumission/VT/:page_id' do
get 'police/new', controller: :soumission_vt, action: :new, as: :new_soumission_vt
end
Hope this will help you finish your migration in time !
;)
I'm new to Ruby on Rails and trying to learn the framework by reading Rails 3 in Action book as well as looking into different online resources. But now I'm struggling with dramatic syntax difference in what book explains, what I see in online resources and what I see in generated code. For example, I'd like to setup my custom routes in routes.rb
The book says
match '/login',
:to => "accounts#login"
Online resource says:
map.login '/login', :controller => 'accounts', :action => 'login'
Another online resource says:
match '/login' => 'accounts#login', :as => 'login'
In my case works only the last one... So the question is why syntax is so different and where to look for syntax explanation for the latest Ruby on Rails?
The first example is fine and is essentially the same as the third example. It just doesn't set up the login paths for you e.g. in your code you won't be able to reference login_path like you can with the third example (the :as => 'login' tells rails to set up the login_path helper).
The online resource (second example) is for Rails v.2.3.11 which is fairly old - we're now on v.3.2. so that resource is out of date. Here is the up to date version.
For start I recommend reading Rails Routing from the Outside In, there are very actual rails guides.
http://apidock.com is a good place where you can read most actual documentation, users comments and changes history.
Here you have wide documentation of match method: http://apidock.com/rails/v3.2.3/ActionDispatch/Routing/Mapper/Base/match
From the looks of some railscasts (this one in particular), it seems like there is some autogeneration of "*_path" variables that not happening for me. in this rails cast, the edit_mutliple_products_path seems to be generated automagically (i don't normally like using that word). When I follow through the same steps and try to access a similar path, i get this:
undefined local variable or method `edit_multiple_distributions_workflows_path' for #<#<Class:0x132b18a68>:0x132af3290>
This is rails 2.X. Rails routes changed in Rails 3. in order to get this route add below to routes.rb:
resources :products do
collection do
post 'edit_multiple'
put 'update_multiple'
end
end
You will be able to access this paths with
edit_multiple_products_url
edit_multiple_products_path
update_multiple_products_url
update_multiple_products_path
instead of edit_multiple_distributions_workflow_path. Btw where did you get this path from? I did not see it in the railscast.
In the given tutorial, which looks like it's from an older Rails, this is the line which would generate the path methods:
map.resources :products, :collection => { :edit_multiple => :post, :update_multiple => :put }
In rails 3, you can see its usage in the docs here: http://guides.rubyonrails.org/routing.html#resource-routing-the-rails-default
In my Rails 2.3 application, the following routes were working properly
map.ajax 'ajax', :controller => 'widgetresponse_controller' , :action => 'getWidgetJson'
When I migrated to Rails 3,
I tried a number of new routes, to get this working but none of them worked.
1.
match 'ajax' => 'widgetresponse#getWidgetJson', :as => :ajax
2.
match 'ajax' => 'widgetresponse_controller#getWidgetJson', :as => :ajax
3.
get 'widgetresponse/getWidgetJson', :as => :ajax
4.
get 'widgetresponse/getWidgetJson'
Its a very basic question to ask, but I don't know what I am doing wrong.
You could try this:
match "/widgetresponse/getWidgetJson/:id" => "widgetresponse#getWidgetJson"
One thing that may have happened before is that things were falling through to the default route which was removed in Ruby on Rails 3 (good idea).
I found this guide:
http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/
really helpful with lot of yummy new rails 3 options.