我試圖創建兩個動作,都去「新」視圖。唯一的區別是我希望new_e_drawing操作運行incrament_e方法,而新操作運行incrament方法。Rails路由:兩個動作指向相同的視圖
def new
@drawing = Drawing.new
@drawing = @drawing.incrament(@drawing)
respond_to do |format|
format.html # new.html.erb
format.json { render json: @drawing }
end
end
def new_e_drawing
@drawing = Drawing.new
@drawing = @drawing.incrament_e(@drawing)
respond_to do |format|
format.html new.html.erb
format.json { render json: @drawing }
end
end
我希望他們都能帶我到名爲「新」的視圖。我不知道如何爲new_e_drawing操作設置路由或respond_to語句。我試過這些沒有成功:
get 'drawings/new' => 'drawings#new_e_drawing'
match 'drawings/new_e_drawing' => 'drawings#new_e_drawing'
感謝您的幫助。
'@ drawing.incrament(@drawing)'自動被護欄產生的?爲什麼要傳遞你調用該方法的對象? – usha