开发者

Basecamp API Rails

I was wondering if someone could do me massive favour..

I really don't understand how to make use of APIs - so I was wondering if, using Basecamp as an example, someone could talk me though the basics.

So far I have an application with a dashboard co开发者_开发技巧ntroller/view, I have put basecamp.rb into my /lib directory, added the following to my application_controller:

  def basecamp_connect
    Basecamp.establish_connection!('XXXXXX.basecamphq.com', 'USER', 'PASS', false)
    @basecamp = Basecamp.new
  end

Obviously changing the required parts to my credentials.

Next up I have added the following to my dashboard_controller:

  def index
    Basecamp::TodoList.find(:all)
  end

Next I presume I have to somehow list the Todos on the dashboard using some sort of loop.

Am I doing the right thing, if so - how on earth do I display all the todo items and if not - what am I doing wrong/missing.

It doesn't have to be todos, anything from Basecamp or any other popular API service would be a good start. It's just that I happen to have a basecamp account!

Thanks,

Danny


Your view expects to have some variables defined. You can loop through those variables and display their content as you want.

So you could do, in your action :

def index
    @list = Basecamp::TodoList.find(:all)
end

Then in your view you have access to the @list variable and you can to the following :

<ul>
    <% @list.each do |item| %>
        <li><%= item.to_json</li>
    <% end %>
</ul>

Replacing the json dump by the elements as you wish to display them of course.

You might want to read the rails guides to get a lot more of informations.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜