How to delete drop down select value in ROR

How to delete a drop down select value by using link_to option.

My code is:

index.html.erb

<%= collection_select(:catvalue, :id, @catvalues, :id, :v_name, {},
class: ‘drop-down’)%>
<%= link_to ‘Destroy’, {:catvalue => :id},method: :delete, data: {
confirm: ‘Are you sure?’ } %>

and my

controller is:

class CatvaluesController < ApplicationController
def index
@catvalue = Catvalue.new
@catvalues = Catvalue.all
@categories = Category.all
end

def destroy
    @catvalue_del = Catvalue.find(params[:id])
    @catvalue_del.destroy
    redirect_to catvalues_path
endend

but its not working
please help me…

Thanks in advance

On 10 April 2014 08:27, santu47 wrote:

def destroy
    @catvalue_del = Catvalue.find(params[:id])
    @catvalue_del.destroy
    redirect_to catvalues_path
end

end

but its not working

First you must work out which bit is not working (that is always the
first thing to do when s/w does not work). Look in development.log to
check that parameters are being passed correctly and the correct
action is being called, if that is ok then you can put debug code in
the controller to work out what is going wrong. puts statements in
the controller will appear in the server terminal window.

Colin

I´m not sure that you can use the collection_select with a link, better
use
a form

try something like:

VIEW

<%= form_tag( :controller =>“Catvalues”, :action => “detroy”, method =>
“delete” do %>

<%= collection_select(:catvalue, :id, @catvalues, :id, :v_name, {},
class: ‘drop-down’)%>

<%= submit_tag(“Destroy”)

<% end %>

´CONTROLLER

def destroy
@catvalue_del = Catvalue.find(catvalues_params[:id])
@catvalue_del.destroy
redirect_to catvalues_path
end

def catvalues_params
params[:catvalues].permit(:id)
end

El jueves, 10 de abril de 2014 09:27:30 UTC+2, santu47 escribió:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs