Hi Chris,

You're not doing any hacks, you're doing what's expected to tell rails
that a route will accept various formats, you should take a look at
the routes guides to undertand how the respond_to method works.

Also, to get JQuery to behave correctly without the ".js" you'll need
to add this somewhere in your application.js:

$(document).ready(function () {

    jQuery.ajaxSetup({
        'beforeSend': function(xhr) {
            xhr.setRequestHeader("Accept", "text/javascript")
    };

});

On the routes issue, as I said before, that's how it works. A route like:

map.schedule "schedule/:id", :controller => "main", :action => "schedule"

Will never call the respond_to with XML as a format unless the client
sends an "Accept: application/xml" as a header and I think you're not
doing this, so, the route with a explicit format is required, this is
no bug, that's exactly how it should behave. Also, avoid mapping URLs
directly as you're doing, these paths should be mapped using
resources.

-
Maurício Linhares
http://codeshooter.wordpress.com/ | http://twitter.com/mauriciojr



On Sun, Aug 23, 2009 at 6:53 PM, Chris
Olsen<[email protected]> wrote:
>
> Maurício Linhares wrote:
>> Without looking at your routes and code it's really had to find a
>> reason.
>
> A big part of the issue is that the initial problems are using standard
> code, the hacks only come into play to make things work.
>
> First issue:
> $("#terms-of-use").click(function() {
>  var url = this.href + ".js"  // <= hack #1 to allow format.js block to
> be called
>  $.get(url, function() {
>    ..
>  })
> })
>
> # controller
> def terms_of_use
>    respond_to do |format|
>      format.html {}
>      format.js {render :action => "terms_of_use", :layout => false}
>    end
>  end
>
> Second issue
> Enter http://foobar.com/schedule/1.xml into browser
>
> #controller
> def schedule
> �...@todos = User.find(params[:id]).todos
>  respond_to do |format|
>    format.html {}
>    format.xml { render :xml => @todos.to_xml }
>  end
> end
>
> # routes.rb
>
> # this won't work to allow the xml request to be made
> map.schedule "schedule/:id", :controller => "main", :action =>
> "schedule"
>
> ## Hack #2: adding the format option will allow it to work
> map.schedule "schedule/id.:format", :controller => "main", :action =>
> "schedule", :format => "html"
>
> --
> Posted via http://www.ruby-forum.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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to