给rails项目写个外部数据调用接口

  客户端http//url调用get_student_courses方法。

  def get_student_courses
     csri=CoursesStuRegInf.all.select{|cs| cs.stu_reg_inf_id==current_user.id&&cs.situation=="已选"}
     courses=[]
     csri.each{|cs| courses << Course.find(cs.course_id) } if csri
     render_data courses
  end


  def render_data data,format=:xml
     if data&&data.size>0
      render format=>data
     else
      render :text=>"无相关数据"
     end
  end

你可能感兴趣的:(xml,http,接口)