내 r_holidays_controller에서 메소드를 호출하려면 어떻게해야합니까?레일의 컨트롤러에서 메서드를 호출하는 방법은 무엇입니까?
여기 내 스크립트를 사용해 보았지만 작동하지 않습니다. 내가 생각
$(function() {
$('#toright').click(function() {
var sel = document.getElementById("left");
var len = sel.options.length;
var w_id = this.getAttribute('w_id');
for (var i = 0; i < len; i++)
{
if(sel.options[i].selected)
{
$.ajax("/r_holidays/w_destroy", {holiday_id: sel.options[i].value, group_id: w_id}).done(function(data){});
}
}
history.go(0);
})
});
내 $.ajax(...)
에서 실수가 있어야합니다.
누구나 아이디어를 얻을 수 있습니까?
여기 내 컨트롤러 코드입니다 :
class RHolidaysController < ApplicationController
before_action :set_r_holiday, only: [:show, :edit, :update, :destroy]
def index
@r_holidays = RHoliday.all
end
def new
@r_holiday = RHoliday.new
end
def edit
end
def create
render json: RHoliday.find_or_create(holiday_id: params[:holiday_id].to_s, group_id: params[:group_id].to_s)
end
def w_create
@r_holiday = RHoliday.new(r_holiday_params)
respond_to do |format|
if @r_holiday.save
format.html { redirect_to @r_holiday, notice: 'RHoliday was successfully created.' }
format.json { render action: 'show', status: :created, location: @r_holiday }
else
format.html { render action: 'new' }
format.json { render json: @r_holiday.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @r_holiday.update(holiday_params)
format.html { redirect_to @r_holiday, notice: 'RHoliday was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @r_holiday.errors, status: :unprocessable_entity }
end
end
end
def destroy
@r_holiday.destroy
respond_to do |format|
format.html { redirect_to holidays_url }
format.json { head :no_content }
end
end
def w_destroy
render json: RHoliday.where(holiday_id: params[:holiday_id].to_s, group_id: params[:group_id].to_s).destroy
end
private
def set_holiday
@r_holiday = RHoliday.find(params[:id])
end
def holiday_params
params.require(:r_holiday).permit(:holiday_id, :group_id)
end
end
그리고 관련 라인 (들) 내하는 Pathes를 검토 , 나는
r_holidays_path GET /r_holidays(.:format) r_holidays#index
POST /r_holidays(.:format) r_holidays#create
new_r_holiday_path GET /r_holidays/new(.:format) r_holidays#new
edit_r_holiday_path GET /r_holidays/:id/edit(.:format) r_holidays#edit
r_holiday_path GET /r_holidays/:id(.:format) r_holidays#show
PATCH /r_holidays/:id(.:format) r_holidays#update
PUT /r_holidays/:id(.:format) r_holidays#update
DELETE /r_holidays/:id(.:format) r_holidays#destroy
편집 ... 내가 나열되지 않습니다 실현 rb는 단지 resources :r_holidays
우리는 컨트롤러 코드와 routes.rb의 관련 부분을 볼 수 있습니까? – akatakritos
경로 파일에 w_destroy 액션을 추가 했습니까? –
나는 그렇지 않았다. 어디에서 추가해야합니까? 방금 route.rb에 r_holidays라는 리소스를 추가했습니다. 그 밖의 무엇을 추가해야합니까? – user3383458