我試圖鏈接到另一個頁面,保存上一次列出的預訂的ID和信息。一個例子是列出預訂表的行,以便顯示信息,然後在點擊後包含一個按鈕來編輯預訂表。我添加了一個按鈕,當我路由到頁面時,出現錯誤。沒有路線匹配: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| %>
\t \t \t <% reviser.reservations.where("status = ?", true).each do |reservation| %>
\t \t \t <script>
\t \t \t \t
\t \t \t \t var total = <%= reviser.reservations.where("status = ?", true).sum(:total) %>;
\t \t \t \t $('#sum').html(total);
\t \t \t \t
\t \t \t </script>
\t \t \t <div class="panel-body" style="">
\t \t \t \t <div style="">
\t \t \t \t <div class="col-md-12 " style="border:3px solid black;height:108px;max-height:108px;min-width:703px;">
\t \t \t \t \t <!-- first column -->
\t \t \t \t \t <div class="row" style="">
\t \t \t \t \t \t <div class="col-sm-3 center " style="">
\t \t \t \t \t \t \t <div style="margin-left:-45px;">
\t \t \t \t \t \t \t \t <%= reservation.reviser.essay_type %>
\t \t \t \t \t \t \t </div>
\t \t \t \t \t \t </div>
\t \t \t \t \t \t <div class="col-sm-2 center " >
\t \t \t \t \t \t \t <div style=" margin-left:-40px;">
\t \t \t \t \t \t \t <% if reservation.document_file_name != nil %>
\t \t \t \t \t \t \t \t <%= link_to "File Download", reservation.document.url(:original, false), class: "btn btn-download" %>
\t \t \t \t \t \t \t \t <% end %>
\t \t \t \t \t \t \t \t <script type="text/javascript">
\t \t \t \t \t \t \t \t \t $(":file").filestyle({buttonName: "btn btn-download", iconName: "fa fa-paper", buttonText: "Choose Word Doc", input: false});
\t \t \t \t \t \t \t \t </script>
\t \t \t \t \t \t \t </div>
\t \t \t \t \t \t </div>
\t \t \t \t \t \t <div class="col-sm-2 center " >
\t \t \t \t \t \t \t <div style="margin-left:35px;">
\t \t \t \t \t \t \t \t Due
\t \t \t \t \t \t \t </div>
\t \t \t \t \t \t \t
\t \t \t \t \t \t </div>
\t \t \t \t \t \t <div class="col-sm-2 center " >
\t \t \t \t \t \t \t <div style="margin-left:70px;">
\t \t \t \t \t \t \t \t <%= link_to "Turn In", edit_reviser_reservation_path(reservation), class: "btn btn-download" %>
\t \t \t \t \t \t \t </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'
我想從本質上編輯另一頁上的預訂!我怎樣才能做到這一點?我試圖創建一個頁面的編輯,但我似乎錯了。
你有資源:在您的路線預訂了嗎? – Hardik127
審校和預約之間的關係是什麼? – oreoluwa
關係是用戶進行預訂,修訂者被包含爲外鍵。我在一個頁面上只有修訂者瀏覽了所有的預訂。當我點擊鏈接時,我希望能夠鏈接到另一個視圖來填寫表單來編輯預訂頁面。希望修訂者能夠將其他信息添加到無保留的列中。 –