2012-10-05 4 views
0

레일스에 레지스터를 편집 할 수있는 양식이있는 응용 프로그램이 있습니다. 여기에 파괴 단추가 있습니다.레일 편집 및보기에서 버튼 제거

현재 작동해야한다고 생각하는 코드가있는 버튼이 있습니다. this is how it looks in the view이 내가 그것을 삭제하려고 코드

<%= link_to t('.destroy', :default => t("helpers.links.destroy")), 
             register_path(register), 
             :method => :delete, 
             :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, 
             :class => 'btn btn-mini btn-danger' %> 

그러나,이다는

+0

레일에서 button_to 메서드를 사용해 보셨습니까? '% = button_to "delete", {: 컨트롤러 => : 이름, : 조치 =>'파괴 ', : id => name.id}, : 방법 => : 삭제 %>' – coletrain

+0

나는 생각하지 않는다 관련이있다. 그러나': data'에': confirm'과': class' 옵션을 넣는 이유는 무엇입니까? 그건 옳지 않아. –

+1

당신의 파괴 행동은 파괴 된 후에 어디로 리디렉션됩니까? 오류 메시지는 편집중인 레지스터 개체가 방금 파괴 된 곳으로 다시 돌아가는 것이 좋습니다. – John

답변

0

"액티브 :: RecordNotFound RegistersController 번호 편집에서"당신의 RegistersController#destroy 액틴에 쓰기, 이것을 시도라고

def destroy 
@register = Register.find(params[:id]) 
if @register.present? 
    @register.destroy 
    redirect_to ..... 
else 
    redirect_to .... or render 'xyz' 
end 
end 

나는 레코드가 데이터베이스에 없기 때문에 'ActiveRecord :: RecordNotFound'오류가 발생합니다.

+0

나는 이것을 작동하게했다! 감사! – Phsyckr