2
我有一個像這樣的控制器操作。 itineraries_controller.rb.js.erb文件中的Rails實例變量
def delete_city
@new_itinerary = params[:new_itinerary] if params[:new_itinerary].present?
@step = params[:step]
if @step == 'two'
@city = City.find(params[:id])
@delete_rec = true
else
@city_item = CityItem.find(params[:id]) rescue nil
end
if @city_item.present?
@itinerary = @city_item.country_item.itinerary rescue nil
@itinerary = Itinerary.unscoped.find(params[:data_id])
if (@itinerary.present? and @itinerary.user_id == current_user.id) or (current_user.moderator?)
@country_item = @city_item.country_item
@city_item.destroy
@country_item.update_column('city_ids', @country_item.city_items.order(:sequence).pluck(:city_id))
@delete_rec = true
end
end
respond_to do |format|
if @delete_rec && @step != 'two'
format.js {render 'step_two.js.erb'}
elsif @delete_rec && @step == "two"
format.js {render 'delete_city_step_2.js.erb'}
else
format.js {render :text => 'fail'}
end
end
end
而且js.erb這樣的:
delete_city_step_2.js.erb
a = $('a.cityCrossBtn[for='+"<%= @city %>"+']')
li = a.closest('.token-input-token-facebook')
li.hide();
我無法找到a
元素。什麼是正確的語法?
它的工作原理。萬分感謝! – RamanSM