ormprog / rails_ama

Ruby/Rails - Ask Me Anything
MIT License
2 stars 0 forks source link

Heroku error : The page you were looking for doesn't exist. #135

Closed ansary14-zz closed 3 years ago

ansary14-zz commented 3 years ago

Screenshot from 2020-11-25 20-40-47

When I click the remove button it shows error like

Screenshot from 2020-11-25 20-40-27

ansary14-zz commented 3 years ago

Here is the heroku build log finance-tracker-ayub-logs-1606315360354.txt

wasifhossain commented 3 years ago

ActionController::RoutingError (No route matches [DELETE] "/user_stocks.1")

lets see the code that rendered the "Remove" button(s)

ansary14-zz commented 3 years ago

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>

ansary14-zz commented 3 years ago

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
wasifhossain commented 3 years ago
<%= 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**

ansary14-zz commented 3 years ago

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

wasifhossain commented 3 years ago

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)
wasifhossain commented 3 years ago

ayub@ayub:~/rails-project/finance-tracker$ rails routes --expanded | grep user_stocks

use singular user_stock after the grep command

ansary14-zz commented 3 years ago

Okay