Solidus current_user - ruby-on-rails

I am trying to add login/logout/sign up links to the front page of a solidus app. In the _login_bar_items partial I put this:
<% if spree_current_user %>
<li>
<%= link_to "Logout", destroy_spree_user_session_path, method: :delete %>
</li>
<% else %>
<li>
<%= link_to "Login", new_spree_user_session_path %>
</li>
<li>
<%= link_to "Register", new_spree_user_registration_path %>
</li>
<% end %>
And I get the error
No route matches [DELETE] "/user/spree_user/logout"
when I click on logout button. The paths are as displayed when I run rails routes.
I also tried if current_user but that didn't work either.
Any suggestions are appreciated.
Edit: Rails Routes output:
Prefix Verb URI Pattern Controller#Action
spree / Spree::Core::Engine
rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show
rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show
update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
Routes for Spree::Core::Engine:
new_spree_user_session GET /user/spree_user/sign_in(.:format) spree/user_sessions#new
spree_user_session POST /user/spree_user/sign_in(.:format) spree/user_sessions#create
destroy_spree_user_session GET /user/spree_user/logout(.:format) spree/user_sessions#destroy
new_spree_user_password GET /user/spree_user/password/new(.:format) spree/user_passwords#new
edit_spree_user_password GET /user/spree_user/password/edit(.:format) spree/user_passwords#edit
spree_user_password PATCH /user/spree_user/password(.:format) spree/user_passwords#update
PUT /user/spree_user/password(.:format) spree/user_passwords#update
POST /user/spree_user/password(.:format) spree/user_passwords#create
cancel_spree_user_registration GET /user/spree_user/cancel(.:format) spree/user_registrations#cancel
new_spree_user_registration GET /user/spree_user/sign_up(.:format) spree/user_registrations#new
edit_spree_user_registration GET /user/spree_user/edit(.:format) spree/user_registrations#edit
spree_user_registration PATCH /user/spree_user(.:format) spree/user_registrations#update
PUT /user/spree_user(.:format) spree/user_registrations#update
DELETE /user/spree_user(.:format) spree/user_registrations#destroy
POST /user/spree_user(.:format) spree/user_registrations#create
new_spree_user_confirmation GET /user/spree_user/confirmation/new(.:format) spree/user_confirmations#new
spree_user_confirmation GET /user/spree_user/confirmation(.:format) spree/user_confirmations#show
POST /user/spree_user/confirmation(.:format) spree/user_confirmations#create
edit_user GET /users/:id/edit(.:format) spree/users#edit
user PATCH /users/:id(.:format) spree/users#update
PUT /users/:id(.:format) spree/users#update
login GET /login(.:format) spree/user_sessions#new
create_new_session POST /login(.:format) spree/user_sessions#create
logout GET /logout(.:format) spree/user_sessions#destroy
signup GET /signup(.:format) spree/user_registrations#new
registration POST /signup(.:format) spree/user_registrations#create
recover_password GET /password/recover(.:format) spree/user_passwords#new
reset_password POST /password/recover(.:format) spree/user_passwords#create
edit_password GET /password/change(.:format) spree/user_passwords#edit
update_password PUT /password/change(.:format) spree/user_passwords#update
confirmation GET /confirm(.:format) spree/user_confirmations#show
checkout_registration GET /checkout/registration(.:format) spree/checkout#registration
update_checkout_registration PUT /checkout/registration(.:format) spree/checkout#update_registration
new_account GET /account/new(.:format) spree/users#new
edit_account GET /account/edit(.:format) spree/users#edit
account GET /account(.:format) spree/users#show
PATCH /account(.:format) spree/users#update
PUT /account(.:format) spree/users#update
DELETE /account(.:format) spree/users#destroy
POST /account(.:format) spree/users#create
admin_unauthorized GET /admin/authorization_failure(.:format) spree/admin/user_sessions#authorization_failure
admin_login GET /admin/login(.:format) spree/admin/user_sessions#new
admin_create_new_session POST /admin/login(.:format) spree/admin/user_sessions#create
admin_logout GET /admin/logout(.:format) spree/admin/user_sessions#destroy
admin_recover_password GET /admin/password/recover(.:format) spree/admin/user_passwords#new
admin_reset_password POST /admin/password/recover(.:format) spree/admin/user_passwords#create
admin_edit_password GET /admin/password/change(.:format) spree/admin/user_passwords#edit
admin_update_password PUT /admin/password/change(.:format) spree/admin/user_passwords#update
root GET / spree/home#index
products GET /products(.:format) spree/products#index
product GET /products/:id(.:format) spree/products#show
locale_set GET /locale/set(.:format) spree/locale#set
select_locale POST /locale/set(.:format) spree/locale#set
update_checkout PATCH /checkout/update/:state(.:format) spree/checkout#update
checkout_state GET /checkout/:state(.:format) spree/checkout#edit
checkout GET /checkout(.:format) spree/checkout#edit
orders_populate GET /orders/populate(.:format) spree/orders#populate_redirect
token_order GET /orders/:id/token/:token(.:format) spree/orders#show
populate_orders POST /orders/populate(.:format) spree/orders#populate
edit_order GET /orders/:id/edit(.:format) spree/orders#edit
order GET /orders/:id(.:format) spree/orders#show
PATCH /orders/:id(.:format) spree/orders#update
PUT /orders/:id(.:format) spree/orders#update
cart GET /cart(.:format) spree/orders#edit
update_cart PATCH /cart(.:format) spree/orders#update
empty_cart PUT /cart/empty(.:format) spree/orders#empty
nested_taxons GET /t/*id(.:format) spree/taxons#show
unauthorized GET /unauthorized(.:format) spree/home#unauthorized
cvv GET /content/cvv(.:format) spree/content#cvv
cart_link GET /cart_link(.:format) spree/store#cart_link
admin_search_users GET /admin/search/users(.:format) spree/admin/search#users
admin_search_products GET /admin/search/products(.:format) spree/admin/search#products
admin_set_locale PUT /admin/locale/set(.:format) spree/admin/locale#set {:format=>:json}
home_admin_dashboards GET /admin/dashboards/home(.:format) spree/admin/dashboards#home
admin_promotion_promotion_rules GET /admin/promotions/:promotion_id/promotion_rules(.:format) spree/admin/promotion_rules#index
POST /admin/promotions/:promotion_id/promotion_rules(.:format) spree/admin/promotion_rules#create
new_admin_promotion_promotion_rule GET /admin/promotions/:promotion_id/promotion_rules/new(.:format) spree/admin/promotion_rules#new
edit_admin_promotion_promotion_rule GET /admin/promotions/:promotion_id/promotion_rules/:id/edit(.:format) spree/admin/promotion_rules#edit
admin_promotion_promotion_rule GET /admin/promotions/:promotion_id/promotion_rules/:id(.:format) spree/admin/promotion_rules#show
PATCH /admin/promotions/:promotion_id/promotion_rules/:id(.:format) spree/admin/promotion_rules#update
PUT /admin/promotions/:promotion_id/promotion_rules/:id(.:format) spree/admin/promotion_rules#update
DELETE /admin/promotions/:promotion_id/promotion_rules/:id(.:format) spree/admin/promotion_rules#destroy
admin_promotion_promotion_actions GET /admin/promotions/:promotion_id/promotion_actions(.:format) spree/admin/promotion_actions#index
POST /admin/promotions/:promotion_id/promotion_actions(.:format) spree/admin/promotion_actions#create
new_admin_promotion_promotion_action GET /admin/promotions/:promotion_id/promotion_actions/new(.:format) spree/admin/promotion_actions#new
edit_admin_promotion_promotion_action GET /admin/promotions/:promotion_id/promotion_actions/:id/edit(.:format) spree/admin/promotion_actions#edit
admin_promotion_promotion_action GET /admin/promotions/:promotion_id/promotion_actions/:id(.:format) spree/admin/promotion_actions#show
PATCH /admin/promotions/:promotion_id/promotion_actions/:id(.:format) spree/admin/promotion_actions#update
PUT /admin/promotions/:promotion_id/promotion_actions/:id(.:format) spree/admin/promotion_actions#update
DELETE /admin/promotions/:promotion_id/promotion_actions/:id(.:format) spree/admin/promotion_actions#destroy
admin_promotion_promotion_codes GET /admin/promotions/:promotion_id/promotion_codes(.:format) spree/admin/promotion_codes#index
admin_promotion_promotion_code_batch_download GET /admin/promotions/:promotion_id/promotion_code_batches/:promotion_code_batch_id/download(.:format) spree/admin/promotion_code_batches#download {:format=>"csv"}
admin_promotion_promotion_code_batches GET /admin/promotions/:promotion_id/promotion_code_batches(.:format) spree/admin/promotion_code_batches#index
POST /admin/promotions/:promotion_id/promotion_code_batches(.:format) spree/admin/promotion_code_batches#create
new_admin_promotion_promotion_code_batch GET /admin/promotions/:promotion_id/promotion_code_batches/new(.:format) spree/admin/promotion_code_batches#new
admin_promotions GET /admin/promotions(.:format) spree/admin/promotions#index
POST /admin/promotions(.:format) spree/admin/promotions#create
new_admin_promotion GET /admin/promotions/new(.:format) spree/admin/promotions#new
edit_admin_promotion GET /admin/promotions/:id/edit(.:format) spree/admin/promotions#edit
admin_promotion GET /admin/promotions/:id(.:format) spree/admin/promotions#show
PATCH /admin/promotions/:id(.:format) spree/admin/promotions#update
PUT /admin/promotions/:id(.:format) spree/admin/promotions#update
DELETE /admin/promotions/:id(.:format) spree/admin/promotions#destroy
admin_promotion_categories GET /admin/promotion_categories(.:format) spree/admin/promotion_categories#index
POST /admin/promotion_categories(.:format) spree/admin/promotion_categories#create
new_admin_promotion_category GET /admin/promotion_categories/new(.:format) spree/admin/promotion_categories#new
edit_admin_promotion_category GET /admin/promotion_categories/:id/edit(.:format) spree/admin/promotion_categories#edit
admin_promotion_category PATCH /admin/promotion_categories/:id(.:format) spree/admin/promotion_categories#update
PUT /admin/promotion_categories/:id(.:format) spree/admin/promotion_categories#update
DELETE /admin/promotion_categories/:id(.:format) spree/admin/promotion_categories#destroy
admin_zones GET /admin/zones(.:format) spree/admin/zones#index
POST /admin/zones(.:format) spree/admin/zones#create
new_admin_zone GET /admin/zones/new(.:format) spree/admin/zones#new
edit_admin_zone GET /admin/zones/:id/edit(.:format) spree/admin/zones#edit
admin_zone GET /admin/zones/:id(.:format) spree/admin/zones#show
PATCH /admin/zones/:id(.:format) spree/admin/zones#update
PUT /admin/zones/:id(.:format) spree/admin/zones#update
DELETE /admin/zones/:id(.:format) spree/admin/zones#destroy
admin_tax_categories GET /admin/tax_categories(.:format) spree/admin/tax_categories#index
POST /admin/tax_categories(.:format) spree/admin/tax_categories#create
new_admin_tax_category GET /admin/tax_categories/new(.:format) spree/admin/tax_categories#new
edit_admin_tax_category GET /admin/tax_categories/:id/edit(.:format) spree/admin/tax_categories#edit
admin_tax_category GET /admin/tax_categories/:id(.:format) spree/admin/tax_categories#show
PATCH /admin/tax_categories/:id(.:format) spree/admin/tax_categories#update
PUT /admin/tax_categories/:id(.:format) spree/admin/tax_categories#update

Try with
<%= link_to "Logout", destroy_spree_user_session_path %>
because your "/user/spree_user/logout" is not defined as DELETE request but as GET request route.

Related

Devise Token Auth - Use POST to sign in. GET is not supported

I installed devise token auth and ng-token-auth in my ruby/angularjs project and I was trying out authentication via facebook/google. Unsuccess, I get the next error =>
{"errors":["Use POST /sign_in to sign in. GET is not supported."]}
My server log shows:
Started GET "/omniauth/facebook/callback?code=AQCJG_Oz26o9PADnpL_arsnTN5E38EFikWZDXiQHXEYki1wPNt4dkqpXHE_8SrbGbweh29VmGQleegapuvVf8jOQmVhtz1prLy7GLRr40i07O24M4iNY8WQFVqKD3TIRmqgsj-puaP61KzUdpR0LHw_yeeguX38FDV_4KjHAHa0D4OLipA6ofd78eXQoEhvdkvtFnguuJGfKt0N6eEj9m1h185F2jkZqaZAwh6lM_VQTnDiwOWy10IHYA62yXWk0MJv28AhhoszC-R7tdFvxAEwn6C7IsMhxY7aBZp6VJwegJyQBBydwXb5QpMnOi4oNLSvi6oKARQkQ5i8Mku5tcqTA&state=8bf6fcfb4dedcf2f22fa3bef875d0e91b63ac0c9b7a8f8a6" for ::1 at 2017-01-29 12:38:34 -0300
Processing by Devise::OmniauthCallbacksController#failure as HTML
Parameters: {"code"=>"AQCJG_Oz26o9PADnpL_arsnTN5E38EFikWZDXiQHXEYki1wPNt4dkqpXHE_8SrbGbweh29VmGQleegapuvVf8jOQmVhtz1prLy7GLRr40i07O24M4iNY8WQFVqKD3TIRmqgsj-puaP61KzUdpR0LHw_yeeguX38FDV_4KjHAHa0D4OLipA6ofd78eXQoEhvdkvtFnguuJGfKt0N6eEj9m1h185F2jkZqaZAwh6lM_VQTnDiwOWy10IHYA62yXWk0MJv28AhhoszC-R7tdFvxAEwn6C7IsMhxY7aBZp6VJwegJyQBBydwXb5QpMnOi4oNLSvi6oKARQkQ5i8Mku5tcqTA", "state"=>"8bf6fcfb4dedcf2f22fa3bef875d0e91b63ac0c9b7a8f8a6"}
Redirected to http://localhost:3000/api/v1/auth/sign_in
Completed 302 Found in 4ms (ActiveRecord: 0.0ms)
What I understand is that my app is starting a Get method instead of POST, but how can I change that?
I've been reading other post about this but no one gives an answer.
My routes:
user_facebook_omniauth_authorize GET|POST /omniauth/facebook(.:format) omniauth_callbacks#passthru
user_facebook_omniauth_callback GET|POST /omniauth/facebook/callback(.:format) omniauth_callbacks#facebook
user_google_oauth2_omniauth_authorize GET|POST /omniauth/google_oauth2(.:format) omniauth_callbacks#passthru
user_google_oauth2_omniauth_callback GET|POST /omniauth/google_oauth2/callback(
Thank you.
EDIT: I add my client side code:
HTML (a simple link to a angular function)
<a class="btn btn-block btn-lg btn-social btn-facebook social-butt" ng-click="facebooksignup()"><span class="fa fa-facebook"></span> RegĂ­strate con Facebook!</a>
My angularjs controller:
$scope.facebooksignup = function(){
$auth.authenticate('facebook')
.then(function(resp) {
// handle success
})
.catch(function(resp) {
// handle errors
});
And my module configuration:
app.config(function($authProvider) {
$authProvider.configure({
apiUrl: 'http://localhost:3000/api/v1',
validateOnPageLoad: false,
authProviderPaths: {
facebook: '/auth/facebook',
google: '/auth/google'
}
});
});

Change redmine routes

www.redmine.org
We use Redmine for asset tracking and I would like to update the URLs. Presently the URLs revolve around issues and does not look right for assets.
I would like to update it so that I would navigate to:
www.domain.com/assets instead of www.domain.com/issues
Using:
Route alias in Rails
I have looked at routes.rb and changed the line:
resources :issues do
to
resources :issues, :path => :assets do
Unfortunately it doesn't work...
**rake routes
rake routes | grep issues
/home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/htmlentities-4.3.1/lib/htmlentities/mappings/expanded.rb:465: warning: key "inodot" is duplicated and overwritten on line 466
[DEPRECATION] `last_comment` is deprecated. Please use `last_description` instead.
preview_new_issue GET|POST|PUT|PATCH /issues/preview/new/:project_id(.:format) previews#issue
preview_edit_issue GET|POST|PUT|PATCH /issues/preview/edit/:id(.:format) previews#issue
preview_issue GET|POST|PUT|PATCH /issues/preview(.:format) previews#issue
auto_complete_issues GET /issues/auto_complete(.:format) auto_completes#issues
issues_context_menu GET|POST /issues/context_menu(.:format) context_menus#issues
issue_changes GET /issues/changes(.:format) journals#index
quoted_issue POST /issues/:id/quoted(.:format) journals#new {:id=>/\d+/}
project_gantt GET /projects/:project_id/issues/gantt(.:format) gantts#show
issues_gantt GET /issues/gantt(.:format) gantts#show
project_calendar GET /projects/:project_id/issues/calendar(.:format) calendars#show
issues_calendar GET /issues/calendar(.:format) calendars#show
project_issues_report GET /projects/:id/issues/report(.:format) reports#issue_report
project_issues_report_details GET /projects/:id/issues/report/:detail(.:format) reports#issue_report_details
new_issues_import GET /issues/imports/new(.:format) imports#new
POST /issues/:object_id/watchers(.:format) watchers#create {:object_type=>"issue"}
DELETE /issues/:object_id/watchers/:user_id(.:format) watchers#destroy {:object_type=>"issue"}
project_copy_issue GET /projects/:project_id/issues/:copy_from/copy(.:format) issues#new
project_issues GET /projects/:project_id/issues(.:format) issues#index
POST /projects/:project_id/issues(.:format) issues#create
new_project_issue GET /projects/:project_id/issues/new(.:format) issues#new
project_issues_new POST /projects/:project_id/issues/new(.:format) issues#new
edit_issue PATCH /issues/:id/edit(.:format) issues#edit
bulk_edit_issues GET|POST /issues/bulk_edit(.:format) issues#bulk_edit
bulk_update_issues POST /issues/bulk_update(.:format) issues#bulk_update
report_issue_time_entries GET /issues/:issue_id/time_entries/report(.:format) timelog#report
issue_time_entries GET /issues/:issue_id/time_entries(.:format) timelog#index
POST /issues/:issue_id/time_entries(.:format) timelog#create
new_issue_time_entry GET /issues/:issue_id/time_entries/new(.:format) timelog#new
issue_relations GET /issues/:issue_id/relations(.:format) issue_relations#index
POST /issues/:issue_id/relations(.:format) issue_relations#create
issues GET /issues(.:format) issues#index
POST /issues(.:format) issues#create
new_issue GET /issues/new(.:format) issues#new
GET /issues/:id/edit(.:format) issues#edit
issue GET /issues/:id(.:format) issues#show
PATCH /issues/:id(.:format) issues#update
PUT /issues/:id(.:format) issues#update
DELETE /issues/:id(.:format) issues#destroy
issues_new POST /issues/new(.:format) issues#new
DELETE /issues(.:format) issues#destroy
POST /projects/:id/repository/:repository_id/revisions/:rev/issues(.:format) repositories#add_related_issue
DELETE /projects/:id/repository/:repository_id/revisions/:rev/issues/:issue_id(.:format) repositories#remove_related_issue
POST /projects/:id/repository/revisions/:rev/issues(.:format) repositories#add_related_issue
DELETE /projects/:id/repository/revisions/:rev/issues/:issue_id(.:format) repositories#remove_related_issue

Change Root in ActiveAdmin

right now my active_admin gem in Rails has a default url of
www.home.com/admin
however the active admin resides in
www.home.com/group/admin
How can I make it so that every link in active admin will route to /group/admin/[next link]
I tried Gmat's solution below and this is what happened:
new_group_admin_user_session GET /group/admin/login(.:format)
active_admin/devise/sessions#new
group_admin_user_session POST /group/admin/login(.:format)
active_admin/devise/sessions#create
destroy_group_admin_user_session DELETE|GET /group/admin/logout(.:format)
active_admin/devise/sessions#destroy
group_admin_user_password POST /group/admin/password(.:format)
active_admin/devise/passwords#create
new_group_admin_user_password GET /group/admin/password/new(.:format)
active_admin/devise/passwords#new
edit_group_admin_user_password GET /group/admin/password/edit(.:format)
active_admin/devise/passwords#edit
PUT /group/admin/password(.:format)
active_admin/devise/passwords#update
group_admin_root /group/admin(.:format) group/admin/dashboard#index
group_root /group(.:format) group/dashboard#index
batch_action_group_admin_leads POST /group/admin/leads/batch_action(.:format)
group/admin/leads#batch_action
group_admin_leads GET /group/admin/leads(.:format)
group/admin/leads#index
POST /group/admin/leads(.:format)
group/admin/leads#create
new_group_admin_lead GET /group/admin/leads/new(.:format) group/admin/leads#new
edit_group_admin_lead GET /group/admin/leads/:id/edit(.:format) group/admin/leads#edit
group_admin_lead GET /group/admin/leads/:id(.:format) group/admin/leads#show
PUT /group/admin/leads/:id(.:format)
group/admin/leads#update
DELETE /group/admin/leads/:id(.:format)
capstonemlg/admin/leads#destroy
group_admin_dashboard /group/admin/dashboard(.:format)
group/admin/dashboard#index
I apologize for the formatting. The point is that all the links www.home.com/group/[anything] is broken.
Try this:
# config/routes.rb
namespace :group do
ActiveAdmin.routes(self)
end
I think you need to customize the ActiveAdmin namespace as well.
http://www.activeadmin.info/docs/2-resource-customization.html
ActiveAdmin.register Post, :namespace => "groups/admin"

Path helper doesn't automatically get object's id anymore?

for some reason this one doesn't work anymore
admin_club_path(club)
but following does work
admin_club_path(club.id)
Anyone know what the reason could be?
This is the error message:
No route matches {:action=>"show", :controller=>"admin/clubs", :id=>#<Club id: 98, name: "1. FSV Mainz 05 II", image: "mainz05.gif", photo_id: 3, league_id: 5, approved: false, permalink: "1-fsv-mainz-05-ii", created_at: "2011-11-22 16:43:13", updated_at: "2011-11-22 16:43:13">}
Apparently it takes the whoe object as id but why?
The routes seem to be alright:
admin_clubs GET /admin/clubs(.:format) {:action=>"index", :controller=>"admin/clubs"}
POST /admin/clubs(.:format) {:action=>"create", :controller=>"admin/clubs"}
new_admin_club GET /admin/clubs/new(.:format) {:action=>"new", :controller=>"admin/clubs"}
edit_admin_club GET /admin/clubs/:id/edit(.:format) {:action=>"edit", :controller=>"admin/clubs"}
admin_club GET /admin/clubs/:id(.:format) {:action=>"show", :controller=>"admin/clubs"}
PUT /admin/clubs/:id(.:format) {:action=>"update", :controller=>"admin/clubs"}
DELETE /admin/clubs/:id(.:format) {:action=>"destroy", :controller=>"admin/clubs"}
club GET /clubs/:id(.:format) {:action=>"show", :controller=>"clubs"}
Lucapette gave me the right hint. I'm using permalink gem which had following in the model:
permalink :name, :unique => true, :to_param => %w(id name)
after I removed the :to_param parameter it all works fine. I will report it to the developer of them gem!
Thanks lucapette and dombesz!

Turning resources into custom routes (Ruby/rails)

Started building an application here. client and server style architecture sending active resources across the wire and storing as activeRecord server side. Managed to get it up and running with a nice example in an O Reilly book except its using scaffold.
Rails routing - custom routes for Resources
is using map.resources from rails 2-
I'm using rails 3 so Its not really applicable and while I did post a question about routes from 2 to 3, I still cant convert this.
So here whats im looking at:
Rake routes with
resources :user_requests
gives:
user_requests GET /user_requests(.:format) {:controller=>"user_requests", :action=>"index"}
POST /user_requests(.:format) {:controller=>"user_requests", :action=>"create"}
new_user_request GET /user_requests/new(.:format) {:controller=>"user_requests", :action=>"new"}
edit_user_request GET /user_requests/:id/edit(.:format) {:controller=>"user_requests", :action=>"edit"}
user_request GET /user_requests/:id(.:format) {:controller=>"user_requests", :action=>"show"}
PUT /user_requests/:id(.:format) {:controller=>"user_requests", :action=>"update"}
DELETE /user_requests/:id(.:format) {:controller=>"user_requests", :action=>"destroy"}
I'd like to remove this and the resources and have my own routes pointing to my own defs.
Heres a quick attempt
match '/user_requests(.:format)' => 'user_requests#create , :via =>:post'
match '/user_requests/:id(.:format)' =>"user_requests#show"
returns almost the exact same as above
/user_requests(.:format) {:controller=>"user_requests", :action=>"create"}
/user_requests/:id(.:format) {:controller=>"user_requests", :action=>"show"}
With the exception of the REST nouns at the start and the links. Its the same yet my own routes dont work.
What do I need to add to my routes to make them do the same thing as resources?
I'm not keeping scaffold as I've been told its never used in the real world. And I will be changing the names of my defs, but one step at a time.
Error that server shows:
Started POST "/user_requests.xml" for 127.0.0.1 at Tue Jul 12 17:13:32 +0100 2011
Processing by UserRequestsController#create as XML
Parameters: {"method"=>"POST", "user_request"=>{"depth"=>3000000, "url"=>"www.stackoverflow.com"}}
SQL (0.1ms) SELECT 1 FROM "user_requests" WHERE ("user_requests"."url" = 'www.stackoverflow.com') LIMIT 1
AREL (0.3ms) INSERT INTO "user_requests" ("updated_at", "depth", "url", "created_at") VALUES ('2011-07-12 16:13:32.765392', 3000000, 'www.stackoverflow.com', '2011-07-12 16:13:32.765392')
Completed 404 Not Found in 17ms
ActionController::RoutingError (No route matches {:controller=>"user_requests", :id=>#<UserRequest id: 6, url: "www.stackoverflow.com", depth: 3000000, created_at: "2011-07-12 16:13:32", updated_at: "2011-07-12 16:13:32">, :action=>"show"}):
app/controllers/user_requests_controller.rb:19:in `create'
app/controllers/user_requests_controller.rb:16:in `create'
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.8ms)
It would guess that line 19 of your UserRequestsController has something like
redirect_to #user_request
which tries to guess a URL for showing a UserRequest object. Rails no longer knows how to do this; you've lost the helper methods generated by resources (such as user_request_path, new_user_request_path, etc).
You can tell Rails to generate the "show" helper method by adding a :as option to your show route, without the _path postfix:
match '/user_requests/:id(.:format)' => "user_requests#show", :as => 'user_request'
You'll now have access to a user_request_path and user_request_url, which Rails can use to find the URL to "show" a UserRequest.

Resources