Closed ansary14-zz closed 3 years ago
Here is the heroku build log finance-tracker-ayub-logs-1606315360354.txt
ActionController::RoutingError (No route matches [DELETE] "/user_stocks.1")
lets see the code that rendered the "Remove" button(s)
render remove button code
<td><%= link_to 'Remove', user_stocks_path(stock), method: :delete, data: {confirm: 'Are you sure?'}, class: "btn btn-sm btn-warning" %></td>
destroy action code
def destroy
stock = Stock.find(params[:id])
user_stock = UserStock.where(user_id: current_user.id, stock_id: stock.id).first
user_stock.destroy
flash[:notice] = "#{stock.ticker} was successfully removed from your portfolio"
redirect_to my_portfolio_path
end
<%= link_to 'Remove', user_stocks_path(stock), method: :delete, data: {confirm: 'Are you sure?'}, class: "btn btn-sm btn-warning" %>
it should be singular user_stock_path(stock)
; not stock**s**
Okay But I confused with this
ayub@ayub:~/rails-project/finance-tracker$ rails routes --expanded | grep user_stocks Prefix | user_stocks URI | /user_stocks(.:format) Controller#Action | user_stocks#create URI | /user_stocks/:id(.:format) Controller#Action | user_stocks#destroy
you get the helper method info from rails routes
run: rails routes | grep -i user_stock
and share the output. you should see user_stock
under the Prefix column for
user_stock DELETE /user_stocks/:id(.:format)
ayub@ayub:~/rails-project/finance-tracker$ rails routes --expanded | grep user_stocks
use singular user_stock
after the grep
command
Okay
When I click the remove button it shows error like