문제

I have a User model in my app and I would like to "find" a User by the name attribute. I don't believe there is any out-of-the-box support for this in batman.js but it is possible that it is just undocumented. I will also need to make some changes to the Rails side to receive and process this type of request as well. Has anyone already tackled this type of problem?

도움이 되었습니까?

해결책

I was mistaken, this functionality exists in Batman out-of-the-box.

YourApp.User.load({name: "wuliwong"}, (err, results) ->
  #do stuff with the results array

The UsersController#index action in Rails now looks like this:

def index
  if params[:name]
    @users = User.where(:name => params[:name])
  else
    @users = User.all
  end
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top