我在视图中的link_to上收到以下错误:
显示/var/www/application_name/app/views/order_log_notes/_form.html.erb,其中第15行引发: 没有路由匹配{:action =>“show”,:controller =>“orders”,:id => nil}缺少必需的密钥:[:id]
似乎忽略了验证。如果选择:status值,一切正常。
型号:
class OrderLogNote < ActiveRecord::Base
belongs_to :order
validates_presence_of :status
end
控制器:
def new
@order_log_note = OrderLogNote.new
end
def create
@order_log_note = OrderLogNote.new(order_log_note_params)
OrderLogNote.where('order_id = ?' ,@order_log_note.orderno).update_all(:isactive => 0)
respond_to do |format|
if @order_log_note.save
format.html { redirect_to order_path(@order_log_note.order_id), notice: 'Order log note was successfully created.' }
format.json { render action: 'show', status: :created, location: @order_log_note }
else
format.html { render action: 'new' }
format.json { render json: @order_log_note.errors, status: :unprocessable_entity }
end
end
end
查看:
<h3>
<%= link_to order_path(:id => params[:order_id]) do%><span class="glyphicon glyphicon-circle-arrow-left"></span><%end%>
</h3>