modified car_log controller, car_log index, renamed add.html.erb to...

modified car_log  controller, car_log index, renamed add.html.erb to new.html.erb, modified routes.rb
parent 706635f2
...@@ -14,6 +14,16 @@ class CarLogsController < ApplicationController ...@@ -14,6 +14,16 @@ class CarLogsController < ApplicationController
car.color = params[:color] car.color = params[:color]
car.brand = params[:brand] car.brand = params[:brand]
car.save car.save
redirect_to "/car_logs"
end
def delete
car_log_to_delete = CarLog.find(params[:id])
car_log_to_delete.destroy!
redirect_to "/car_logs"
end
def new
render "/car_logs/new.html.erb"
end end
end end
\ No newline at end of file
...@@ -40,11 +40,16 @@ ...@@ -40,11 +40,16 @@
<td></td> <td></td>
<td></td> <td></td>
<td><%= car.brand %></td> <td><%= car.brand %></td>
<td></td>
<td></td>
<td></td>
<td><%= button_to "Remove Car", { id: car.id },
method: :delete, data: { confirm: "Are you sure?" } %></td>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<hr> <hr>
<a href= "/car_logs/add">Add New Car</a> <a href= "/car_logs/new"><button>Add New Car</button></a>
<hr> <hr>
<a href= "/">Go back to Homepage</a> <a href= "/">Go back to Homepage</a>
\ No newline at end of file
Rails.application.routes.draw do Rails.application.routes.draw do
root to: "pages#index" root to: "pages#index"
get"/car_logs", to: "car_logs#index" get"/car_logs", to: "car_logs#index"
get"/car_logs/add", to: "car_logs#add" get"/car_logs/new", to: "car_logs#new"
get"/car_logs/delete", to: "car_logs#delete" get"/car_logs/delete", to: "car_logs#delete"
post"/car_logs/add", to: "car_logs#add" post"/car_logs/add", to: "car_logs#add"
post"/car_logs/delete", to: "car_logs#delete" delete"/car_logs", to: "car_logs#delete"
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment