【问题标题】:No route matches :id=>nil没有路线匹配:id=>nil
【发布时间】:2016-07-05 23:59:06
【问题描述】:

我正在尝试链接到另一个页面,该页面保留先前列出的预订的 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'

我想在另一个页面上编辑预订!!我怎样才能做到这一点?我尝试为页面创建编辑,但我似乎错了。

【问题讨论】:

  • 您的路线中有资源:预订吗?
  • reviser和reservation是什么关系?
  • 关系是用户预约,reviser作为外键包含。我在一个页面上,只有修订者才能查看所有已作出的保留。当我单击链接时,我希望能够链接到另一个视图以填写表格以编辑预订页面。希望修订者能够将其他数量的信息添加到保留的零列中。

标签: html ruby-on-rails forms controller routes


【解决方案1】:

快速修复:

edit_reviser_reservation_path(reservation.reviser, reservation)

【讨论】:

  • 这行得通!现在,如果您想检查一下,我在下一页的表格有问题!!!会发的非常感谢!!
  • 太棒了。您可以将附加问题发布为 Github gist,或在 SO 上提出另一个问题。
  • 我想通了!但我有一个关于样式的不同问题,我将发布!谢谢!!
猜你喜欢
  • 2018-09-22
  • 2015-10-15
  • 2012-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-18
相关资源
最近更新 更多