Rails Destroy Record link doesn't do anything -


i'm attempting destroy nested record, destroy button appears work , redirect above models page record still shows there.

here partial nested record:

<p>     <tr>         <td><%= time_delta.start %></td>         <td><%= time_delta.length %></td>         <td>             <%=                 link_to 'destroy time delta',                 [time_delta.stock, time_delta],                 method: :delete,                 data: { confirm: 'are sure?' }             %>         </td>     </tr> </p> 

heres show above class

<!-- shows stock--> <h1> stock </h1> <table>      <tr>         <th>stock</th>         <th>hashtag</th>             </tr>         <tr>             <td><%= @stock.name %></td>             <td><%= @stock.hashtag %></td>         </tr> </table>  <!-- shows time detlas--> <h3>timedeltas: </h2> <%= render @stock.time_deltas %>  <!-- creates time delta--> <h3>add timedelta:</h2> <%= render "time_deltas/form" %>  <%= link_to 'back', stocks_path%> <%= link_to 'edit', edit_stock_path(@stock)%> 

here controller time delta (the nested class)

class timedeltascontroller < applicationcontroller    def create     @stock = stock.find(params[:stock_id])     @time_delta = @stock.time_deltas.create(time_delta_params)     redirect_to stock_path(@stock)   end    def destroy     @stock = stock.find(params[:stock_id])      @time_delta = @stock.time_deltas.create(params[:time_delta_id])      # @time_delta = @stock.time_deltas.create(time_delta_params)     @time_delta.destroy     redirect_to stock_path(@stock)   end    private      def time_delta_params       params.require(:time_delta).permit(:start, :length)     end end 

you creating new time_delta on action , calling destroy on it. need find time_delta want destroy.
change second line in destroy action to:
@time_delta = @stock.time_deltas.find(params[:id])


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -