0

please help me i newbie on rails and jquery i try get all values from array #mychannels id element on html in my view.

JS AJAX

$(document).ready(function() {
  $('#mychannels').change(function () {
    $.ajax({
      type: "GET",
      contentType: "dados/json",
      url: "/suporte/chamados?empresa_id=91194",
      success: function(data){
        alert(data);
      }
    });
  });
});

Controller

  def get_data
    @company = Company.find(params[:company_id])
    @servers = Server.find(:all, :conditions => ["company_id = ? AND action != 3", @company.id])
    @channels_list = Channels.where("channel = 't' and company_id = 91194")

My View

<%= select_tag "mychannels",options_for_select(@channels_list.map { |e|
                                 [e.name+" - "+e.server.name, e.id]})  %>

I am trying to read the data that comes from the controller throw to an array and display it in the select_tag of the view.

could you help me with the code

1 Answer 1

3

You need to update your controller action adding the render method and adding the values you want to get in your jQuery success callback.

Controller

def get_data
  @company = Company.find(params[:company_id])
  @servers = Server.find(:all, :conditions => ["company_id = ? AND action != 3", @company.id])
  @channels_list = Channels.where("channel = 't' and company_id = 91194")
  render json: { company: @company.to_json, servers: @servers.to_json, channels_list: @channels_list.to_json }
end
Sign up to request clarification or add additional context in comments.

1 Comment

thankyou now i get all data from company and study the code :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.