Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3.1 app cannot destroy mysql2 object
    primarykey
    data
    text
    <p>I'm new to rails and i've created a web app to manage my warehouses. I've the following problem: when I click on "destroy" button (see attached below), the related object isn't delate from mysql2 database. Anyone can help me?</p> <p>This is controller</p> <p>`</p> <pre><code> class PositionsController &lt; ApplicationController #before_filter :check_count, :only =&gt; [:destroy] # GET /positions # GET /positions.xml def index @positions = Position.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml =&gt; @positions } end end # GET /positions/1 # GET /positions/1.xml def show @position = Position.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml =&gt; @position } end end # GET /positions/new # GET /positions/new.xml def new @position = Position.new respond_to do |format| format.html # new.html.erb format.xml { render :xml =&gt; @position } end end # GET /positions/1/edit def edit @position = Position.find(params[:id]) end # POST /positions # POST /positions.xml def create @position = Position.new(params[:position]) respond_to do |format| if @position.save flash[:notice] = 'Position was successfully created.' format.html { redirect_to(@position) } format.xml { render :xml =&gt; @position, :status =&gt; :created, :location =&gt; @position } else format.html { render :action =&gt; "new" } format.xml { render :xml =&gt; @position.errors, :status =&gt; :unprocessable_entity } end end end # PUT /positions/1 # PUT /positions/1.xml def update @position = Position.find(params[:id]) respond_to do |format| if @position.update_attributes(params[:position]) flash[:notice] = 'Position was successfully updated.' format.html { redirect_to(@position) } format.xml { head :ok } else format.html { render :action =&gt; "edit" } format.xml { render :xml =&gt; @position.errors, :status =&gt; :unprocessable_entity } end end end # DELETE /positions/1 # DELETE /positions/1.xml def destroy @position = Position.find(params[:id]) @position.destroy respond_to do |format| format.html { redirect_to(positions_url) } format.xml { head :ok } end end private def check_count @position_to_destroy = Logicalwarehouse.find(params[:id]) if @position_to_destroy.warehouse.count &gt; 0 flash[:notice] = "Non puoi cancellare una posizione in uso" redirect_to :positions end end end </code></pre> <p>This is model </p> <pre><code>class Position &lt; ActiveRecord::Base has_many :warehouses has_many :locks_on_warehouses, :class_name =&gt; "Warehouse", :foreign_key =&gt; "lock_by_position_id" has_many :users belongs_to :registry </code></pre> <p>end</p> <p>and this is view</p> <pre><code> &lt;h1&gt;Listing positions&lt;/h1&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;Name&lt;/th&gt; &lt;/tr&gt; &lt;% for position in @positions %&gt; &lt;tr&gt; &lt;td&gt;&lt;%=h position.name %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= link_to 'Show', position %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= link_to 'Edit', edit_position_path(position) %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= link_to 'Destroy', position, :confirm =&gt; 'Are you sure?', :method =&gt; :delete %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;% end %&gt; &lt;/table&gt; &lt;br /&gt; &lt;%= link_to 'New position', new_position_path %&gt; </code></pre> <p>Other "actions" such as update,edit,show,index works fine but when I destroy an element, it doesn't give me any errors on web server console but the element isn't removed from database.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload