In my project, I try to update a record, so once I click "update" I am redirected to the previous page, as if the record was updated since the parameters are passed through. However, instead of updating, the porduction.log show a return of a 302 redirect, but with no accessing a database to change the values in the paramters.
Controller:
def show
@hour = HourLog.find(params[:id])
@status = @hour.status
end
def update
@hour = HourLog.find(params[:id])
if @hour.update(update_hour_params)
redirect_to '/hours'
else
redirect_to "/hours/#{id}"
end
end
View(show.html.erb):
<div class="table-responsive">
<%= form_for(@hour, url: hour_path, method: :patch) do |f| %>
<table class="table table-striped">
<thead>
<tr id="dashtexttable">
<th>User</th>
<th>Assignment</th>
<th>Hours</th>
<th>Supervisor/Location</th>
<th>Date</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody>
<tr id="dashfield">
<td><%= @hour.user.first_name + ' ' + @hour.user.last_name %></td>
<td><%= f.text_field :assignment, :value => @hour.assignment %></td>
<td><%= f.number_field :hours, in: 0.5..12.0, step: 0.5, :value => @hour.hours %></td>
<td> <%= f.text_field :supervisor, :value => @hour.supervisor %></td>
<td><%= f.date_field :date, :value => @hour.date %></td>
<td><%= f.hidden_field :status, :value => 'Confirmed'%>
<%= f.submit 'Update'%></td>
<%end %>
<td><%= link_to 'Delete', hour_path(@hour), method: :delete %></td>
</tr>
</tbody>
</table>
</div>
Routes:
root 'welcome#index'
get '/signup' => 'users#new'
resources :users
get '/login' => 'sessions#new'
post '/login' => 'sessions#create'
delete '/logout' => 'sessions#destroy'
post '/hours/new' => 'hours#create'
resources :hours
get '/leaderboard' => 'leaderboard#index'
get '/essay' => 'essay#index'
resources :essay
Any help would be great, thank you!
Aucun commentaire:
Enregistrer un commentaire