ActionController::ParameterMissing in TagsController#create
up vote
0
down vote
favorite
I am attempting to trigger a destroy action from an index page for tags attached to multiple records. However, when the action is triggered I get the above error in the create action. The error does not occur when the create action is invoked. My code is as seen below.
Tag Controller
class TagsController < ApplicationController
before_action :require_user, only: [:edit, :update, :destroy]
before_action :set_search
def new
@tag = Tag.new
end
def create
tag = Tag.create(tag_params)
if tag.save
redirect_to tags_path
else
redirect_to sign_up_path
end
end
def destroy
@tag = Tag.find(params[:tag_id])
@tag.destroy
redirect_to tags_path
end
private
def tag_params
params.require(:tag).permit(:name)
end
end
Routes
Rails.application.routes.draw do
# For details on the DSL available within this file, see
http://guides.rubyonrails.org/routing.html
resources :recipes do
resources :ingredients, :steps
put :favorite, on: :member
end
resources :users
get 'recipes' => 'recipes#index'
get 'recipes/:id' => 'recipes#show'
get 'signup' => 'users#new'
get 'tags' => 'tags#index'
get 'new_tags' => 'tags#new'
post 'tags' => 'tags#create'
delete 'tags' => 'tags#destroy'
get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
root 'recipes#index'
end
Index
<%= link_to 'New Tag', new_tags_path(@tag) %>
<% Tag.find_each do |tag| %>
<%= tag.name %>
<%= link_to 'Delete Tag', @tag,
method: :destroy,
data: { confirm: 'Are you sure?' } %>
<% end %>
ruby-on-rails controller routes destroy
add a comment |
up vote
0
down vote
favorite
I am attempting to trigger a destroy action from an index page for tags attached to multiple records. However, when the action is triggered I get the above error in the create action. The error does not occur when the create action is invoked. My code is as seen below.
Tag Controller
class TagsController < ApplicationController
before_action :require_user, only: [:edit, :update, :destroy]
before_action :set_search
def new
@tag = Tag.new
end
def create
tag = Tag.create(tag_params)
if tag.save
redirect_to tags_path
else
redirect_to sign_up_path
end
end
def destroy
@tag = Tag.find(params[:tag_id])
@tag.destroy
redirect_to tags_path
end
private
def tag_params
params.require(:tag).permit(:name)
end
end
Routes
Rails.application.routes.draw do
# For details on the DSL available within this file, see
http://guides.rubyonrails.org/routing.html
resources :recipes do
resources :ingredients, :steps
put :favorite, on: :member
end
resources :users
get 'recipes' => 'recipes#index'
get 'recipes/:id' => 'recipes#show'
get 'signup' => 'users#new'
get 'tags' => 'tags#index'
get 'new_tags' => 'tags#new'
post 'tags' => 'tags#create'
delete 'tags' => 'tags#destroy'
get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
root 'recipes#index'
end
Index
<%= link_to 'New Tag', new_tags_path(@tag) %>
<% Tag.find_each do |tag| %>
<%= tag.name %>
<%= link_to 'Delete Tag', @tag,
method: :destroy,
data: { confirm: 'Are you sure?' } %>
<% end %>
ruby-on-rails controller routes destroy
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am attempting to trigger a destroy action from an index page for tags attached to multiple records. However, when the action is triggered I get the above error in the create action. The error does not occur when the create action is invoked. My code is as seen below.
Tag Controller
class TagsController < ApplicationController
before_action :require_user, only: [:edit, :update, :destroy]
before_action :set_search
def new
@tag = Tag.new
end
def create
tag = Tag.create(tag_params)
if tag.save
redirect_to tags_path
else
redirect_to sign_up_path
end
end
def destroy
@tag = Tag.find(params[:tag_id])
@tag.destroy
redirect_to tags_path
end
private
def tag_params
params.require(:tag).permit(:name)
end
end
Routes
Rails.application.routes.draw do
# For details on the DSL available within this file, see
http://guides.rubyonrails.org/routing.html
resources :recipes do
resources :ingredients, :steps
put :favorite, on: :member
end
resources :users
get 'recipes' => 'recipes#index'
get 'recipes/:id' => 'recipes#show'
get 'signup' => 'users#new'
get 'tags' => 'tags#index'
get 'new_tags' => 'tags#new'
post 'tags' => 'tags#create'
delete 'tags' => 'tags#destroy'
get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
root 'recipes#index'
end
Index
<%= link_to 'New Tag', new_tags_path(@tag) %>
<% Tag.find_each do |tag| %>
<%= tag.name %>
<%= link_to 'Delete Tag', @tag,
method: :destroy,
data: { confirm: 'Are you sure?' } %>
<% end %>
ruby-on-rails controller routes destroy
I am attempting to trigger a destroy action from an index page for tags attached to multiple records. However, when the action is triggered I get the above error in the create action. The error does not occur when the create action is invoked. My code is as seen below.
Tag Controller
class TagsController < ApplicationController
before_action :require_user, only: [:edit, :update, :destroy]
before_action :set_search
def new
@tag = Tag.new
end
def create
tag = Tag.create(tag_params)
if tag.save
redirect_to tags_path
else
redirect_to sign_up_path
end
end
def destroy
@tag = Tag.find(params[:tag_id])
@tag.destroy
redirect_to tags_path
end
private
def tag_params
params.require(:tag).permit(:name)
end
end
Routes
Rails.application.routes.draw do
# For details on the DSL available within this file, see
http://guides.rubyonrails.org/routing.html
resources :recipes do
resources :ingredients, :steps
put :favorite, on: :member
end
resources :users
get 'recipes' => 'recipes#index'
get 'recipes/:id' => 'recipes#show'
get 'signup' => 'users#new'
get 'tags' => 'tags#index'
get 'new_tags' => 'tags#new'
post 'tags' => 'tags#create'
delete 'tags' => 'tags#destroy'
get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
root 'recipes#index'
end
Index
<%= link_to 'New Tag', new_tags_path(@tag) %>
<% Tag.find_each do |tag| %>
<%= tag.name %>
<%= link_to 'Delete Tag', @tag,
method: :destroy,
data: { confirm: 'Are you sure?' } %>
<% end %>
ruby-on-rails controller routes destroy
ruby-on-rails controller routes destroy
asked Nov 11 at 1:08
dsteinbr1
153
153
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
This route:
delete 'tags' => 'tags#destroy'
means "/tags" with no id parameter.
You have to tell the router that you want a part of the url used as the :tag_id
delete 'tags/:tag_id' => 'tags#destroy'
Anyway, I'd recommend you to stick with rails conventions and just use
resources :tags
and on the controller
@tag = Tag.find(params[:id])
I'm not sure why are you setting the routes manually, if you are new to Rails read this link: https://guides.rubyonrails.org/routing.html
You even have this lines
get 'recipes' => 'recipes#index'
get 'recipes/:id' => 'recipes#show'
which are unnecessary since resources :recipes
already creates them.
I have made the changes you suggest above however I am still receiving the following error... ActionController::ParameterMissing in TagsController#create param is missing or the value is empty: tag
– dsteinbr1
Nov 11 at 1:58
Can you show the log when you do the destroy request? I don't understand why you are getting an error on the create action.
– arieljuod
Nov 11 at 2:04
Started POST "/tags" for 127.0.0.1 at 2018-11-10 20:07:14 -0600 Processing by TagsController#create as HTML Parameters: {"authenticity_token"=>"4OWmSZoqtiZHeTPnVEdawCLF3aVpRcYDkXgoMDElNPX/rDw2YxXvdJM+fMMpyUuBDLRVpv3HaFtGSftQsI/FsQ=="} Completed 400 Bad Request in 2ms (ActiveRecord: 0.0ms) ActionController::ParameterMissing (param is missing or the value is empty: tag): app/controllers/tags_controller.rb:27:intag_params' app/controllers/tags_controller.rb:10:in
create'
– dsteinbr1
Nov 11 at 2:10
It looks like for some reason the destroy action is running the create instead?
– dsteinbr1
Nov 11 at 2:10
do you have the rails-ujs gem installed? by default alink_to
can't do a request with DELETE method, rails uses rails-ujs to handle that edgeguides.rubyonrails.org/…
– arieljuod
Nov 11 at 3:17
|
show 1 more comment
up vote
0
down vote
accepted
The error stemmed from a combination of issues in the Link To statement in the view. The Link as it should be written is below...
<%= link_to 'Delete Tag', tag_path(tag),
method: :delete,
data: { confirm: 'Are you sure?' } %>
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
This route:
delete 'tags' => 'tags#destroy'
means "/tags" with no id parameter.
You have to tell the router that you want a part of the url used as the :tag_id
delete 'tags/:tag_id' => 'tags#destroy'
Anyway, I'd recommend you to stick with rails conventions and just use
resources :tags
and on the controller
@tag = Tag.find(params[:id])
I'm not sure why are you setting the routes manually, if you are new to Rails read this link: https://guides.rubyonrails.org/routing.html
You even have this lines
get 'recipes' => 'recipes#index'
get 'recipes/:id' => 'recipes#show'
which are unnecessary since resources :recipes
already creates them.
I have made the changes you suggest above however I am still receiving the following error... ActionController::ParameterMissing in TagsController#create param is missing or the value is empty: tag
– dsteinbr1
Nov 11 at 1:58
Can you show the log when you do the destroy request? I don't understand why you are getting an error on the create action.
– arieljuod
Nov 11 at 2:04
Started POST "/tags" for 127.0.0.1 at 2018-11-10 20:07:14 -0600 Processing by TagsController#create as HTML Parameters: {"authenticity_token"=>"4OWmSZoqtiZHeTPnVEdawCLF3aVpRcYDkXgoMDElNPX/rDw2YxXvdJM+fMMpyUuBDLRVpv3HaFtGSftQsI/FsQ=="} Completed 400 Bad Request in 2ms (ActiveRecord: 0.0ms) ActionController::ParameterMissing (param is missing or the value is empty: tag): app/controllers/tags_controller.rb:27:intag_params' app/controllers/tags_controller.rb:10:in
create'
– dsteinbr1
Nov 11 at 2:10
It looks like for some reason the destroy action is running the create instead?
– dsteinbr1
Nov 11 at 2:10
do you have the rails-ujs gem installed? by default alink_to
can't do a request with DELETE method, rails uses rails-ujs to handle that edgeguides.rubyonrails.org/…
– arieljuod
Nov 11 at 3:17
|
show 1 more comment
up vote
0
down vote
This route:
delete 'tags' => 'tags#destroy'
means "/tags" with no id parameter.
You have to tell the router that you want a part of the url used as the :tag_id
delete 'tags/:tag_id' => 'tags#destroy'
Anyway, I'd recommend you to stick with rails conventions and just use
resources :tags
and on the controller
@tag = Tag.find(params[:id])
I'm not sure why are you setting the routes manually, if you are new to Rails read this link: https://guides.rubyonrails.org/routing.html
You even have this lines
get 'recipes' => 'recipes#index'
get 'recipes/:id' => 'recipes#show'
which are unnecessary since resources :recipes
already creates them.
I have made the changes you suggest above however I am still receiving the following error... ActionController::ParameterMissing in TagsController#create param is missing or the value is empty: tag
– dsteinbr1
Nov 11 at 1:58
Can you show the log when you do the destroy request? I don't understand why you are getting an error on the create action.
– arieljuod
Nov 11 at 2:04
Started POST "/tags" for 127.0.0.1 at 2018-11-10 20:07:14 -0600 Processing by TagsController#create as HTML Parameters: {"authenticity_token"=>"4OWmSZoqtiZHeTPnVEdawCLF3aVpRcYDkXgoMDElNPX/rDw2YxXvdJM+fMMpyUuBDLRVpv3HaFtGSftQsI/FsQ=="} Completed 400 Bad Request in 2ms (ActiveRecord: 0.0ms) ActionController::ParameterMissing (param is missing or the value is empty: tag): app/controllers/tags_controller.rb:27:intag_params' app/controllers/tags_controller.rb:10:in
create'
– dsteinbr1
Nov 11 at 2:10
It looks like for some reason the destroy action is running the create instead?
– dsteinbr1
Nov 11 at 2:10
do you have the rails-ujs gem installed? by default alink_to
can't do a request with DELETE method, rails uses rails-ujs to handle that edgeguides.rubyonrails.org/…
– arieljuod
Nov 11 at 3:17
|
show 1 more comment
up vote
0
down vote
up vote
0
down vote
This route:
delete 'tags' => 'tags#destroy'
means "/tags" with no id parameter.
You have to tell the router that you want a part of the url used as the :tag_id
delete 'tags/:tag_id' => 'tags#destroy'
Anyway, I'd recommend you to stick with rails conventions and just use
resources :tags
and on the controller
@tag = Tag.find(params[:id])
I'm not sure why are you setting the routes manually, if you are new to Rails read this link: https://guides.rubyonrails.org/routing.html
You even have this lines
get 'recipes' => 'recipes#index'
get 'recipes/:id' => 'recipes#show'
which are unnecessary since resources :recipes
already creates them.
This route:
delete 'tags' => 'tags#destroy'
means "/tags" with no id parameter.
You have to tell the router that you want a part of the url used as the :tag_id
delete 'tags/:tag_id' => 'tags#destroy'
Anyway, I'd recommend you to stick with rails conventions and just use
resources :tags
and on the controller
@tag = Tag.find(params[:id])
I'm not sure why are you setting the routes manually, if you are new to Rails read this link: https://guides.rubyonrails.org/routing.html
You even have this lines
get 'recipes' => 'recipes#index'
get 'recipes/:id' => 'recipes#show'
which are unnecessary since resources :recipes
already creates them.
answered Nov 11 at 1:40
arieljuod
5,91211121
5,91211121
I have made the changes you suggest above however I am still receiving the following error... ActionController::ParameterMissing in TagsController#create param is missing or the value is empty: tag
– dsteinbr1
Nov 11 at 1:58
Can you show the log when you do the destroy request? I don't understand why you are getting an error on the create action.
– arieljuod
Nov 11 at 2:04
Started POST "/tags" for 127.0.0.1 at 2018-11-10 20:07:14 -0600 Processing by TagsController#create as HTML Parameters: {"authenticity_token"=>"4OWmSZoqtiZHeTPnVEdawCLF3aVpRcYDkXgoMDElNPX/rDw2YxXvdJM+fMMpyUuBDLRVpv3HaFtGSftQsI/FsQ=="} Completed 400 Bad Request in 2ms (ActiveRecord: 0.0ms) ActionController::ParameterMissing (param is missing or the value is empty: tag): app/controllers/tags_controller.rb:27:intag_params' app/controllers/tags_controller.rb:10:in
create'
– dsteinbr1
Nov 11 at 2:10
It looks like for some reason the destroy action is running the create instead?
– dsteinbr1
Nov 11 at 2:10
do you have the rails-ujs gem installed? by default alink_to
can't do a request with DELETE method, rails uses rails-ujs to handle that edgeguides.rubyonrails.org/…
– arieljuod
Nov 11 at 3:17
|
show 1 more comment
I have made the changes you suggest above however I am still receiving the following error... ActionController::ParameterMissing in TagsController#create param is missing or the value is empty: tag
– dsteinbr1
Nov 11 at 1:58
Can you show the log when you do the destroy request? I don't understand why you are getting an error on the create action.
– arieljuod
Nov 11 at 2:04
Started POST "/tags" for 127.0.0.1 at 2018-11-10 20:07:14 -0600 Processing by TagsController#create as HTML Parameters: {"authenticity_token"=>"4OWmSZoqtiZHeTPnVEdawCLF3aVpRcYDkXgoMDElNPX/rDw2YxXvdJM+fMMpyUuBDLRVpv3HaFtGSftQsI/FsQ=="} Completed 400 Bad Request in 2ms (ActiveRecord: 0.0ms) ActionController::ParameterMissing (param is missing or the value is empty: tag): app/controllers/tags_controller.rb:27:intag_params' app/controllers/tags_controller.rb:10:in
create'
– dsteinbr1
Nov 11 at 2:10
It looks like for some reason the destroy action is running the create instead?
– dsteinbr1
Nov 11 at 2:10
do you have the rails-ujs gem installed? by default alink_to
can't do a request with DELETE method, rails uses rails-ujs to handle that edgeguides.rubyonrails.org/…
– arieljuod
Nov 11 at 3:17
I have made the changes you suggest above however I am still receiving the following error... ActionController::ParameterMissing in TagsController#create param is missing or the value is empty: tag
– dsteinbr1
Nov 11 at 1:58
I have made the changes you suggest above however I am still receiving the following error... ActionController::ParameterMissing in TagsController#create param is missing or the value is empty: tag
– dsteinbr1
Nov 11 at 1:58
Can you show the log when you do the destroy request? I don't understand why you are getting an error on the create action.
– arieljuod
Nov 11 at 2:04
Can you show the log when you do the destroy request? I don't understand why you are getting an error on the create action.
– arieljuod
Nov 11 at 2:04
Started POST "/tags" for 127.0.0.1 at 2018-11-10 20:07:14 -0600 Processing by TagsController#create as HTML Parameters: {"authenticity_token"=>"4OWmSZoqtiZHeTPnVEdawCLF3aVpRcYDkXgoMDElNPX/rDw2YxXvdJM+fMMpyUuBDLRVpv3HaFtGSftQsI/FsQ=="} Completed 400 Bad Request in 2ms (ActiveRecord: 0.0ms) ActionController::ParameterMissing (param is missing or the value is empty: tag): app/controllers/tags_controller.rb:27:in
tag_params' app/controllers/tags_controller.rb:10:in
create'– dsteinbr1
Nov 11 at 2:10
Started POST "/tags" for 127.0.0.1 at 2018-11-10 20:07:14 -0600 Processing by TagsController#create as HTML Parameters: {"authenticity_token"=>"4OWmSZoqtiZHeTPnVEdawCLF3aVpRcYDkXgoMDElNPX/rDw2YxXvdJM+fMMpyUuBDLRVpv3HaFtGSftQsI/FsQ=="} Completed 400 Bad Request in 2ms (ActiveRecord: 0.0ms) ActionController::ParameterMissing (param is missing or the value is empty: tag): app/controllers/tags_controller.rb:27:in
tag_params' app/controllers/tags_controller.rb:10:in
create'– dsteinbr1
Nov 11 at 2:10
It looks like for some reason the destroy action is running the create instead?
– dsteinbr1
Nov 11 at 2:10
It looks like for some reason the destroy action is running the create instead?
– dsteinbr1
Nov 11 at 2:10
do you have the rails-ujs gem installed? by default a
link_to
can't do a request with DELETE method, rails uses rails-ujs to handle that edgeguides.rubyonrails.org/…– arieljuod
Nov 11 at 3:17
do you have the rails-ujs gem installed? by default a
link_to
can't do a request with DELETE method, rails uses rails-ujs to handle that edgeguides.rubyonrails.org/…– arieljuod
Nov 11 at 3:17
|
show 1 more comment
up vote
0
down vote
accepted
The error stemmed from a combination of issues in the Link To statement in the view. The Link as it should be written is below...
<%= link_to 'Delete Tag', tag_path(tag),
method: :delete,
data: { confirm: 'Are you sure?' } %>
add a comment |
up vote
0
down vote
accepted
The error stemmed from a combination of issues in the Link To statement in the view. The Link as it should be written is below...
<%= link_to 'Delete Tag', tag_path(tag),
method: :delete,
data: { confirm: 'Are you sure?' } %>
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
The error stemmed from a combination of issues in the Link To statement in the view. The Link as it should be written is below...
<%= link_to 'Delete Tag', tag_path(tag),
method: :delete,
data: { confirm: 'Are you sure?' } %>
The error stemmed from a combination of issues in the Link To statement in the view. The Link as it should be written is below...
<%= link_to 'Delete Tag', tag_path(tag),
method: :delete,
data: { confirm: 'Are you sure?' } %>
answered Nov 11 at 2:33
dsteinbr1
153
153
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244960%2factioncontrollerparametermissing-in-tagscontrollercreate%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown