我试图link_to另一个页面,保留上一个列出的预订的ID和信息。一个例子是列出我的预订表的行,以便它显示信息,然后包括一个按钮,用于在点击后编辑预订表。我添加了一个按钮,当我被路由到页面时,我收到了一个错误。
错误:
ActionController::UrlGenerationError in Reservations#your_reservations
No route matches {:action=>"edit", :controller=>"reservations", :id=>nil, :reviser_id=>#<Reservation id: 107, user_id: 4, reviser_id: 1, missing required keys: [:id]
我如何获得此ID?
代码底部的Html.view(your_reservations)“是link_to”
<% @revisers.each do |reviser| %>
<% reviser.reservations.where("status = ?", true).each do |reservation| %>
<script>
var total = <%= reviser.reservations.where("status = ?", true).sum(:total) %>;
$('#sum').html(total);
</script>
<div class="panel-body" style="">
<div style="">
<div class="col-md-12 " style="border:3px solid black;height:108px;max-height:108px;min-width:703px;">
<!-- first column -->
<div class="row" style="">
<div class="col-sm-3 center " style="">
<div style="margin-left:-45px;">
<%= reservation.reviser.essay_type %>
</div>
</div>
<div class="col-sm-2 center " >
<div style=" margin-left:-40px;">
<% if reservation.document_file_name != nil %>
<%= link_to "File Download", reservation.document.url(:original, false), class: "btn btn-download" %>
<% end %>
<script type="text/javascript">
$(":file").filestyle({buttonName: "btn btn-download", iconName: "fa fa-paper", buttonText: "Choose Word Doc", input: false});
</script>
</div>
</div>
<div class="col-sm-2 center " >
<div style="margin-left:35px;">
Due
</div>
</div>
<div class="col-sm-2 center " >
<div style="margin-left:70px;">
<%= link_to "Turn In", edit_reviser_reservation_path(reservation), class: "btn btn-download" %>
</div>
<% end %>
<% end %>
预订控制器
before_action :find_reservation, only: [:edit, :update]
before_filter :require_permission, only: [:edit, :update]
def edit
end
def update
if @reservation.update(reservation_params)
redirect_to your_reservations_path
else
render 'edit'
end
end
protect_from_forgery except: [:your_reservations]
def your_reservations
@revisers = current_user.revisers
@user = current_user
@reservations = @reservations
end
def completed_file_upload
end
def find_reservation
@reservation = Reservation.find(params[:id])
end
def require_permission
@reservation = Reservation.find(params[:id])
if current_user.id != @reservation.user_id
redirect_to root_path, notice: "Sorry, you're not allowed"
end
end
的routes.rb
get '/your_reservations' => 'reservations#your_reservations'
get '/your_reservations/completed_file_upload' => 'reservations#completed_file_upload'
我想在另一页上实际编辑预订!!我怎样才能做到这一点?我尝试为页面创建一个编辑,但我似乎错了。
答案 0 :(得分:1)
快速修复:
edit_reviser_reservation_path(reservation.reviser, reservation)