Routing Error | No route matches [POST] "/subscriptions/create" - ruby-on-rails

I'm new to Ruby on Rails and I'm working on an application that contains form used to create a new nominee ( store it in the database)
I get the problem with this instruction of the form:
<%= form_for :subscription, :url => {:controller => "subscriptions", :action => "create"} do |f| %>
this is the error:
Routing Error
No route matches [POST] "/subscriptions/create"
rake routes
Prefix Verb URI Pattern Controller#Action
subscriptions_create GET /subscriptions/create(.:format) subscriptions#create
subscriptions_index GET /subscriptions/index(.:format) subscriptions#index
articles_index GET /articles/index(.:format) articles#index
new_admin_user_session GET /admin/login(.:format) active_admin/devise/sessions#new
admin_user_session POST /admin/login(.:format) active_admin/devise/sessions#create
destroy_admin_user_session DELETE|GET /admin/logout(.:format) active_admin/devise/sessions#destroy
admin_user_password POST /admin/password(.:format) active_admin/devise/passwords#create
new_admin_user_password GET /admin/password/new(.:format) active_admin/devise/passwords#new
edit_admin_user_password GET /admin/password/edit(.:format) active_admin/devise/passwords#edit
PATCH /admin/password(.:format) active_admin/devise/passwords#update
PUT /admin/password(.:format) active_admin/devise/passwords#update
admin_root GET /admin(.:format) admin/dashboard#index
batch_action_admin_admin_users POST /admin/admin_users/batch_action(.:format) admin/admin_users#batch_action
admin_admin_users GET /admin/admin_users(.:format) admin/admin_users#index
POST /admin/admin_users(.:format) admin/admin_users#create
new_admin_admin_user GET /admin/admin_users/new(.:format) admin/admin_users#new
edit_admin_admin_user GET /admin/admin_users/:id/edit(.:format) admin/admin_users#edit
admin_admin_user GET /admin/admin_users/:id(.:format) admin/admin_users#show
PATCH /admin/admin_users/:id(.:format) admin/admin_users#update
PUT /admin/admin_users/:id(.:format) admin/admin_users#update
DELETE /admin/admin_users/:id(.:format) admin/admin_users#destroy
batch_action_admin_contacts POST /admin/contacts/batch_action(.:format) admin/contacts#batch_action
admin_contacts GET /admin/contacts(.:format) admin/contacts#index
POST /admin/contacts(.:format) admin/contacts#create
new_admin_contact GET /admin/contacts/new(.:format) admin/contacts#new
edit_admin_contact GET /admin/contacts/:id/edit(.:format) admin/contacts#edit
admin_contact GET /admin/contacts/:id(.:format) admin/contacts#show
PATCH /admin/contacts/:id(.:format) admin/contacts#update
PUT /admin/contacts/:id(.:format) admin/contacts#update
DELETE /admin/contacts/:id(.:format) admin/contacts#destroy
admin_dashboard GET /admin/dashboard(.:format) admin/dashboard#index
admin_comments GET /admin/comments(.:format) admin/comments#index
POST /admin/comments(.:format) admin/comments#create
admin_comment GET /admin/comments/:id(.:format) admin/comments#show
articles GET /articles(.:format) articles#index
POST /articles(.:format) articles#create
new_article GET /articles/new(.:format) articles#new
edit_article GET /articles/:id/edit(.:format) articles#edit
article GET /articles/:id(.:format) articles#show
PATCH /articles/:id(.:format) articles#update
PUT /articles/:id(.:format) articles#update
DELETE /articles/:id(.:format) articles#destroy
welcome_sponsor GET /welcome/sponsor(.:format) welcome#sponsor
welcome_photo GET /welcome/photo(.:format) welcome#photo
welcome_index GET /welcome/index(.:format) welcome#index
root GET / welcome#index
best regard

As you can see from the lines below:
Prefix Verb URI Pattern Controller#Action
subscriptions_create GET /subscriptions/create(.:format) subscriptions#create
you have got a route for subscriptions_create but it needs to be POST instead of GET. Simply update this route in your routes.rb file in your config folder to be a POST instead of a GET.

As you can see from this line
subscriptions_create GET /subscriptions/create(.:format), that route is only available when using GET HTTP method.
You need to change your routes.rb file for subscriptions to accept POST instead of GET. The easiest way would be to add resources :subscriptions, which will add all standard CRUD routes for resource.

Related

Active Admin : How to restrict active admin routes in production

I developed a normal (Post) like rails application that has features of posting articles with pictures then I opted for active admin in regulating the post as in (admin user), so the application doesnt have any other user expect the admin that will regulate post at backend, how do I restrict these admin routes page like if a normal web visitor attempts to visit the routes it wont be accessible ?
new_admin_user_session GET /admin/login(.:format) active_admin/devise/sessions#new
admin_user_session POST /admin/login(.:format) active_admin/devise/sessions#create
destroy_admin_user_session DELETE|GET /admin/logout(.:format) active_admin/devise/sessions#destroy
new_admin_user_password GET /admin/password/new(.:format) active_admin/devise/passwords#new
edit_admin_user_password GET /admin/password/edit(.:format) active_admin/devise/passwords#edit
admin_user_password PATCH /admin/password(.:format) active_admin/devise/passwords#update
PUT /admin/password(.:format) active_admin/devise/passwords#update
POST /admin/password(.:format) active_admin/devise/passwords#create
admin_root GET /admin(.:format) admin/dashboard#index
batch_action_admin_admin_users POST /admin/admin_users/batch_action(.:format) admin/admin_users#batch_action
admin_admin_users GET /admin/admin_users(.:format) admin/admin_users#index
POST /admin/admin_users(.:format) admin/admin_users#create
new_admin_admin_user GET /admin/admin_users/new(.:format) admin/admin_users#new
edit_admin_admin_user GET /admin/admin_users/:id/edit(.:format) admin/admin_users#edit
admin_admin_user GET /admin/admin_users/:id(.:format) admin/admin_users#show
PATCH /admin/admin_users/:id(.:format) admin/admin_users#update
PUT /admin/admin_users/:id(.:format) admin/admin_users#update
DELETE /admin/admin_users/:id(.:format) admin/admin_users#destroy
batch_action_admin_articles POST /admin/articles/batch_action(.:format) admin/articles#batch_action
admin_articles GET /admin/articles(.:format) admin/articles#index
POST /admin/articles(.:format) admin/articles#create
new_admin_article GET /admin/articles/new(.:format) admin/articles#new
edit_admin_article GET /admin/articles/:id/edit(.:format) admin/articles#edit
admin_article GET /admin/articles/:id(.:format) admin/articles#show
PATCH /admin/articles/:id(.:format) admin/articles#update
PUT /admin/articles/:id(.:format) admin/articles#update
DELETE /admin/articles/:id(.:format) admin/articles#destroy
admin_dashboard GET /admin/dashboard(.:format) admin/dashboard#index
admin_comments GET /admin/comments(.:format) admin/comments#index
POST /admin/comments(.:format) admin/comments#create
admin_c
the only way i have seen is by integrating an authorization system in AA, here is the link:
https://activeadmin.info/13-authorization-adapter.html#managing-access-to-pages

Needed to fill in the questions for URI path, controller, and the action/method after I place in routes commands, but I wasn't sure want to look for

The pertinent line in the output from the rails routes command for dealing with listing all articles is as follows:
articles GET /articles(.:format) articles#index
The URI path to your new view in the above line is _____________.
The controller is ___________.
The action or method in the above controller is _____________
*********OUTPUT FROM BASH COMMAND************************
ec2-user:~/environment/ruby_labs/blog (master) $ rails routes
Prefix Verb URI Pattern Controller#Action
welcome_index GET /welcome/index(.:format) welcome#index
new_articles GET /articles/new(.:format) articles#new
edit_articles GET /articles/edit(.:format) articles#edit
articles GET /articles(.:format) articles#show
PATCH /articles(.:format) articles#update
PUT /articles(.:format) articles#update
DELETE /articles(.:format) articles#destroy
POST /articles(.:format) articles#create
root GET / welcome#index
article GET /articles/:id(.:format) articles#show
GET /articles(.:format) articles#index
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
The question above reviews rails conventions and file structure.
You can learn more about it here: https://guides.rubyonrails.org/v2.3/routing.html
The answers to above the questions would be the following:
The URI path to your new view in the above line is /articles/index
The controller is articles_controller
The action or method in the above controller is #index

Missing :id routes on resource creation

My rake routes after creating the resource :articles says I should get:
Prefix Verb URI Pattern Controller#Action
articles GET /articles(.:format) articles#index
POST /articles(.:format) articles#create
new_article GET /articles/new(.:format) articles#new
edit_article GET /articles/:id/edit(.:format) articles#edit
article GET /articles/:id(.:format) articles#show
PATCH /articles/:id(.:format) articles#update
PUT /articles/:id(.:format) articles#update
DELETE /articles/:id(.:format) articles#destroy
root GET / welcome#index
However my routes are always missing those with :id in them.
Prefix Verb URI Pattern Controller#Action
articles POST /articles(.:format) articles#create
new_articles GET /articles/new(.:format) articles#new
edit_articles GET /articles/edit(.:format) articles#edit
GET /articles(.:format) articles#show
PATCH /articles(.:format) articles#update
PUT /articles(.:format) articles#update
DELETE /articles(.:format) articles#destroy
root GET / welcome#index
I guess you have added to the routes:
resource :articles
instead of:
resources :article
Singular resource is used when you don't have to provide id to identify resource. Ie.: when you operate on current user's profile: /profile

Active Admin CollectionAction route being skipped, action treated as ID

I'm trying to create a collection_action in ActiveAdmin which allows me to rearrange the position after a drop and add. I want to be able to drag and drop the list in the index and have the new positions sent via Ajax through a post request
This is what I have so far:
ActiveAdmin.register Subscriber do
collection_action :reorder, :method => :post do
end
controller do
def reorder
#item = ResponsiveWeb.find(params[:id])
#item.position = params[:position]
#item.saved
render nothing: true
end
private
def item_params
params.require(:responsive_web).permit(:id, :position)
end
end
These are the routes:
Prefix Verb URI Pattern Controller#Action
new_admin_user_session GET /admin/login(.:format) active_admin/devise/sessions#new
admin_user_session POST /admin/login(.:format) active_admin/devise/sessions#create
destroy_admin_user_session DELETE|GET /admin/logout(.:format) active_admin/devise/sessions#destroy
admin_user_password POST /admin/password(.:format) active_admin/devise/passwords#create
new_admin_user_password GET /admin/password/new(.:format) active_admin/devise/passwords#new
edit_admin_user_password GET /admin/password/edit(.:format) active_admin/devise/passwords#edit
PATCH /admin/password(.:format) active_admin/devise/passwords#update
PUT /admin/password(.:format) active_admin/devise/passwords#update
admin_root GET /admin(.:format) admin/dashboard#index
batch_action_admin_admin_users POST /admin/admin_users/batch_action(.:format) admin/admin_users#batch_action
admin_admin_users GET /admin/admin_users(.:format) admin/admin_users#index
POST /admin/admin_users(.:format) admin/admin_users#create
new_admin_admin_user GET /admin/admin_users/new(.:format) admin/admin_users#new
edit_admin_admin_user GET /admin/admin_users/:id/edit(.:format) admin/admin_users#edit
admin_admin_user PATCH /admin/admin_users/:id(.:format) admin/admin_users#update
PUT /admin/admin_users/:id(.:format) admin/admin_users#update
DELETE /admin/admin_users/:id(.:format) admin/admin_users#destroy
admin_dashboard GET /admin/dashboard(.:format) admin/dashboard#index
sort_admin_responsive_web POST /admin/responsive_webs/:id/sort(.:format) admin/responsive_webs#sort
reorder_admin_responsive_webs POST /admin/responsive_webs/reorder(.:format) admin/responsive_webs#reorder
However when I reorder I get the 404 not found error and when I check the error logs it says, Couldn't find ResponsiveWeb with id=reorder.
Any help will be greatly appreciated!
To declare a collection action, active admin provide another dsl. Here is an example. You can try that.
collection_action :reorder, method: :post do
# your resources or whatever you need
end
One thing, active admin resource DSL provide a permit_params, so you don't need to declare it on your controller.
Hope this answer helps.
Here is the reference:
http://activeadmin.info/docs/8-custom-actions.html

How to configure routes.rb for get access to localhost:3000/admin

I follow the tutorial of active_admin at this url: activeadmin
I tried to add it to a project that already exists followings this differents steps:
Add it to my Gemfile gem 'activeadmin', github: 'activeadmin'
Run the follow command because i already install devise rails g active_admin:install --skip-users
And rake db:migrate && rails server
My problem is that when i want to access to localhost:3000/admin i get this error Unknown Action AbstractController::ActionNotFound
Here is my routes.rb
Rails.application.routes.draw do
config = ActiveAdmin::Devise.config
config[:controllers][:sessions] = 'sessions'
config[:controllers][:registrations] = 'registrations'
config[:as] = 'admin'
devise_for :users, config
# Login / Logout routes
namespace :v1, path: '/' do
devise_scope :user do
post '/sessions', to: 'sessions#create'
post '/registrations', to: 'registrations#create'
delete '/sessions', to: 'sessions#destroy'
end
# User routes
get '/user', to: 'users#show'
patch '/user/update', to: 'users#update'
end
ActiveAdmin.routes(self)
end
I'm using rails 4.2.1 and ruby 2.2.2
UPDATE 09/06
rake routes
new_admin_user_session GET /admin/login(.:format) sessions#new
admin_user_session POST /admin/login(.:format) sessions#create
destroy_admin_user_session DELETE|GET /admin/logout(.:format) sessions#destroy
admin_user_password POST /admin/password(.:format) active_admin/devise/passwords#create
new_admin_user_password GET /admin/password/new(.:format) active_admin/devise/passwords#new
edit_admin_user_password GET /admin/password/edit(.:format) active_admin/devise/passwords#edit
PATCH /admin/password(.:format) active_admin/devise/passwords#update
PUT /admin/password(.:format) active_admin/devise/passwords#update
cancel_admin_user_registration GET /admin/cancel(.:format) registrations#cancel
admin_user_registration POST /admin(.:format) registrations#create
new_admin_user_registration GET /admin/sign_up(.:format) registrations#new
edit_admin_user_registration GET /admin/edit(.:format) registrations#edit
PATCH /admin(.:format) registrations#update
PUT /admin(.:format) registrations#update
DELETE /admin(.:format) registrations#destroy
v1_sessions POST /sessions(.:format) v1/sessions#create
v1_registrations POST /registrations(.:format) v1/registrations#create
DELETE /sessions(.:format) v1/sessions#destroy
v1_user GET /user(.:format) v1/users#show
v1_user_update PATCH /user/update(.:format) v1/users#update
admin_root GET /admin(.:format) admin/dashboard#index
admin_dashboard GET /admin/dashboard(.:format) admin/dashboard#index
batch_action_admin_admin_users POST /admin/admin_users/batch_action(.:format) admin/admin_users#batch_action
admin_admin_users GET /admin/admin_users(.:format) admin/admin_users#index
POST /admin/admin_users(.:format) admin/admin_users#create
new_admin_admin_user GET /admin/admin_users/new(.:format) admin/admin_users#new
edit_admin_admin_user GET /admin/admin_users/:id/edit(.:format) admin/admin_users#edit
admin_admin_user GET /admin/admin_users/:id(.:format) admin/admin_users#show
PATCH /admin/admin_users/:id(.:format) admin/admin_users#update
PUT /admin/admin_users/:id(.:format) admin/admin_users#update
DELETE /admin/admin_users/:id(.:format) admin/admin_users#destroy
admin_comments GET /admin/comments(.:format) admin/comments#index
POST /admin/comments(.:format) admin/comments#create
admin_comment GET /admin/comments/:id(.:format) admin/comments#show
and the log
F, [2015-06-09T10:45:02.609120 #2451] FATAL -- :
AbstractController::ActionNotFound (AbstractController::ActionNotFound):
/home/snoobie/.rvm/gems/ruby-2.2.2/bundler/gems/activeadmin-0b4b22871fd3/lib/active_admin/base_controller.rb:29:in `only_render_implemented_actions'
I hope someone can explain me what i'm doing wrong.
Thank you !
I solved it by using rails_admin, more easly to agregate to the project. If someone need more informations about the process to add rails_admin in rails project. Please let a comment and i will explain it in details.

Resources