Greg
--
Posted via http://www.ruby-forum.com/.
index.js.erb
and in it, render your response
buts its worse idea, return json, and build dom
Ivan Nastyukhin
diei...@me.com
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>
I'm not sure to understand.
You think it's better to return json and than build the dom from the
javascript?
> yep u can
>
> index.js.erb
>
> and in it, render your response
>
> buts its worse idea, return json, and build dom
I'm not sure to understand.
You think it's better to return json and than build the dom from the
javascript?
On Thu, Jun 3, 2010 at 8:05 AM, Gregory Mar <li...@ruby-forum.com> wrote:
> Hi,
> I am working on a mobile device dev using javascript and I use a remote
> Rails app for the backend.
> I query the backend using Ajax, and I would like to know if from my
> controller I can return a partial in response to the ajax request?
>
If you're asking if you can return it specifically from the controller
rather than through an rjs template / view, the answer is yes.
render :update do |page|
page.which_ever_method_you_need
end
But I tend to agree with Ivan. If you're trying to get html to your
javascript app, it'll probably be easier in the long run to send json
and build the html on the client.
HTH,
Bill
If you don't agree how would you do it?
> It's faster/lighter to do it that way.
>
> However, you often break DRY* as you have two sets of logic used to
> create
> markup from a dataset (one in Rails and one is JS). So I'm not sure I
> agree
> with Ivan.
If you don't agree how would you do it?
I'd do it as the OP requested, have a partial used in both places and return that.
This is exactly what I planned to do until you said it would be better
to return json
This is exactly what I planned to do until you said it would be better
to return json
mm, u can do itbut1) u should write yet anothe action at controller, its not like REST
2) its will be more slower, than render at mobile device, from json
if request.xhr?render :partial => "whatever"end
How much slower is a big thing though. If you can cache the response then it should remove the load from Rails, if the content is small/gzipped over the air time should be negligibly larger than JSON and if it takes a few milliseconds longer than JSON parsing/DOM creation on a client device it's not the end of the world.
Optimal performance isn't necessarily the only criteria in success...
if request.xhr?render :partial => "whatever"endif developers, from my team, write this, i curse too much for such)
yep, if u will be cache the render time, will be good. but data with u send, will be huge.Insert big html into dom, is slower then build its in js.
Out of interest, what's your problem with the above code?
Premature optimisation is the root of all evil...
Out of interest, what's your problem with the above code?its crutch, for incomprehensible thing
Premature optimisation is the root of all evil...yep, but i'm thinking, that write 1-10 LOC in js, witch will be build partial for each json element, its not optimisation, its "by default" use case,
this is my opinionof course, i will not be try to convince u)
Out of interest, what's your problem with the above code?its crutch, for incomprehensible thingSorry, I don't understand - could you rephrase...
The problem is we don't know how complex his logic is that converts the data structure to HTML. I think you have a fairly simple display if it's only 10 LOC in JS to build it.
This shows how we're obviously working on different projects :-)
I'd take, I'd go with a partial first and optimise to JSON/JS rendering if required later.
Out of interest, what's your problem with the above code?its crutch, for incomprehensible thingSorry, I don't understand - could you rephrase...U should not insert if request.xhr?u can create view, with build js ( show.js.erb)and in its view call render, but with js escape
The problem is we don't know how complex his logic is that converts the data structure to HTML. I think you have a fairly simple display if it's only 10 LOC in JS to build it.10LOC, yep its for simple results, such twitter post, github notify, or something elsein my project, we use haml, we can simplify use jshaml tools, for simplify create dom elements in js
This shows how we're obviously working on different projects :-)I would say, as far as we are working on projects with a completely different level of thoughtfulness interface ;-)