what am I missing? param is missing or the value is empty: feedback2
<%= link_to " #{@like_count} Like", feedback2s_path(:query => “Likes”, :id => feedback2.id) %>
I’ve permitted the :id in the feedback_params
what am I missing? param is missing or the value is empty: feedback2
<%= link_to " #{@like_count} Like", feedback2s_path(:query => “Likes”, :id => feedback2.id) %>
I’ve permitted the :id in the feedback_params
ok, i removed the require here, not sure how it will affect the form?
#params.require(:feedback2).permit(:topic, :category, :content, :feedback2_id, :priority, :status, :query, :user_id, :subscribe, :id ) params.permit(:topic, :category, :content, :feedback2_id, :priority, :status, :query, :user_id, :subscribe, :id )
Can you post the controller code and the exact message? You are probably doing a param.require
that expects something you did not send
class Feedback2sController < ApplicationController before_action :set_feedback2, only: [:show, :edit, :update, :destroy]
def index @count = 0
case params[:query] when ‘Likes’ likes when ‘Newest’ @feedback2s = Feedback2.order(‘created_at DESC’) when’Oldest’ @feedback2s = Feedback2.order(‘created_at ASC’) when ‘Most_Likes’ @feedback2s = Feedback2.order(‘likes DESC’) when’Fewest_Likes’ @feedback2s = Feedback2.order(‘likes ASC’) when’Opened’ @feedback2s = Feedback2.where(:status => ‘Opened’) @count = @feedback2s.size when’Investigating’ @feedback2s = Feedback2.where(:status => ‘Investigating’) @count = @feedback2s.size when’Closed’ @feedback2s = Feedback2.where(:status => ‘Closed’) @count = @feedback2s.size when’Low’ @feedback2s = Feedback2.where(:priority => ‘Low’) @count = @feedback2s.size when’Medium’ @feedback2s = Feedback2.where(:priority => ‘Medium’) @count = @feedback2s.size when’High’ @feedback2s = Feedback2.where(:priority => ‘High’) @count = @feedback2s.size else @feedback2s = Feedback2.where(‘topic LIKE :search OR content LIKE :search’, search: “%#{params[:search]}%”) @count = @feedback2s.size end
#@count = @feedback2s.size
end
def show end
def new @feedback2 = Feedback2.new end
def edit end
def create @feedback2 = Feedback2.new(feedback2_params)
respond_to do |format|
if @feedback2.save
format.html { redirect_to @feedback2, notice: 'Feedback2 was successfully created.' }
format.json { render :show, status: :created, location: @feedback2 }
notify_users
else
format.html { render :new }
format.json { render json: @feedback2.errors, status: :unprocessable_entity }
end
end
end
def update respond_to do |format| if @feedback2.update(feedback2_params) format.html { redirect_to @feedback2, notice: ‘Feedback2 was successfully updated.’ } format.json { render :show, status: :ok, location: @feedback2 } notify_users else format.html { render :edit } format.json { render json: @feedback2.errors, status: :unprocessable_entity } end end end
def destroy @feedback2.destroy respond_to do |format| format.html { redirect_to feedback2s_url, notice: ‘Feedback2 was successfully destroyed.’ } format.json { head :no_content } end end
def likes
# check if already registered a like... likes table...
found = Likes.where(user_id: current_user.id, like_id: feedback2_params[:id])
if found.exists?
respond_to do |format|
format.html { redirect_to feedback2s_url, notice: 'Like was already registered.' }
format.json { head :no_content }
end
else
likes = Feedback2.find(feedback2_params[:id])
likes.likes += 1
respond_to do |format|
if Likes.create(user_id: current_user.id, like_id: feedback2_params[:id] )
format.html { redirect_to feedback2s_url, notice: 'Like was successfully registered.' }
format.json { head :no_content }
else
format.html { render :new }
format.json { render json: likes.errors, status: :unprocessable_entity }
end
end
end end
private # Use callbacks to share common setup or constraints between actions.
def notify_users
puts "just created feedback"
category = feedback2_params[:category]
status = feedback2_params[:status]
priority = feedback2_params[:priority]
@email_user = Feedback2notify.where(category: category).where(status: status).where(priority: priority)
if @email_user.size > 0
puts 'we have some users, here are they are'
@email_user.each do |ue|
if ue.enable == true
puts ue.email << " will be notified"
# FeedbackNotificationMailer.notify_email(ue).deliver_later
FeedbackNotificationMailer.notify_email(ue).deliver_now
end
end
else
puts 'nothing here'
end
#binding.pry
# lookup records in feeback2notify and mail out emails
# @notifyuser = Feedback2notify.where(hash)
end
def set_feedback2
@feedback2 = Feedback2.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def feedback2_params
#params.require(:feedback2).permit(:topic, :category, :content, :feedback2_id, :priority, :status, :query, :user_id, :subscribe, :id )
params.permit(:topic, :category, :content, :feedback2_id, :priority, :status, :query, :user_id, :subscribe, :id )
end
end
here is the controller, I had a form for the majority of the code, but also added a incremental counter (like button), and I put it in the required params, but had to remove require(:feedback).
Looking at your feedback2_params
, the first version was clearly the problem, as the require(:feedback2)
is what was causing the error message when used with the button.
When you create a regular form you do something like this:
<%= form model: @user do |form| <% end %>
<%= form.text_field :name %>
<%= form.text_field :email %>
<%= form.text_field :password %>
<% end
When when the form is submitted it reaches the controller as the hash user: { name, :email, :password }
. This is why you do params.require(:user).permit(:name, :email, :password)
However, when you use a anchor like this:
<%= link_to @user, path: user_path(@user, name: "Joe", email: "joe@example.com", password: "12356"%>
Then the params need to be accessed as params.permit(:name, :email, :password)
So if you are using the feedback2_params
for a form
and an a
you are going to have a problem, because one needs the require
and the other cannot have it.
You could try this and see if it works
params.fetch(:feedback2, {}).permit(:topic, :category, :content, :feedback2_id, :priority, :status, :query, :user_id, :subscribe, :id )