[rails 3.2.2]

I perform an ajax call :
...
$.ajax
url: " /backoffice/expenses/rate"
type: "GET"
dataType: "json"
data:
project_id: $('#project_id').val()
code: $(this).val()
success: (result) ->
alert result
$('#expense_price').val(result)

in the controller , I am correctly receiving the js call
Started GET "/backoffice/expenses/rate?project_id=7&code=1
Processing by Backoffice::ExpensesController#rate as JSON
..
Completed 200 OK in 2004ms (Views: 0.5ms | ActiveRecord: 2.6ms)

in my controller
def partner_rate
...
@rate = "10.00"
render :json => @rate # for testing purpose only
end

and the alert result is not displayed , what am I missing here ?

thanks for your feedback

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Javier Quarite at Mar 26, 2012 at 4:53 pm

    On Mon, Mar 26, 2012 at 11:48 AM, Erwin wrote:

    [rails 3.2.2]

    I perform an ajax call :
    ...
    $.ajax
    url: " /backoffice/expenses/rate"
    type: "GET"
    dataType: "json"
    data:
    project_id: $('#project_id').val()
    code: $(this).val()
    success: (result) ->
    alert result
    $('#expense_price').val(result)
    So you are going to the method Rate in Expenses controller right?

    in the controller , I am correctly receiving the js call
    Started GET "/backoffice/expenses/rate?project_id=7&code=1
    Processing by Backoffice::ExpensesController#rate as JSON
    ..
    Completed 200 OK in 2004ms (Views: 0.5ms | ActiveRecord: 2.6ms)

    in my controller
    def partner_rate
    ...
    @rate = "10.00"
    render :json => @rate # for testing purpose only
    end

    and the alert result is not displayed , what am I missing here ?

    thanks for your feedback
    and this is you PartnerRate method, so I guess you have to do

    $.ajax
    url: " /backoffice/expenses/partner_rate"
    ....

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Erwin at Mar 26, 2012 at 8:48 pm
    thanks for your feedback .. maybe so mistake typing this post ,
    however the url is fine , as the action is correctly reached ..
    if I use :
    render :text => @rate
    then the result is displayed ..
    so it's not an Ajax call issue , rather something I don't get right
    with json

    can I use render :json => @ rate

    @rate being a String object ? I tried
    render :json => {:name => "joe"} # i.e example
    and the result is also received back

    so what could be wrong withe render :json => "<String> ???

    On Mar 26, 6:53 pm, Javier Quarite wrote:
    On Mon, Mar 26, 2012 at 11:48 AM, Erwin wrote:
    [rails 3.2.2]
    I perform an ajax call :
    ...
    $.ajax
    url: " /backoffice/expenses/rate"
    type: "GET"
    dataType: "json"
    data:
    project_id: $('#project_id').val()
    code: $(this).val()
    success: (result) ->
    alert result
    $('#expense_price').val(result)
    So you are going to the method Rate in Expenses controller right?








    in the controller , I am correctly receiving the js call
    Started GET "/backoffice/expenses/rate?project_id=7&code=1
    Processing by Backoffice::ExpensesController#rate as JSON
    ..
    Completed 200 OK in 2004ms (Views: 0.5ms | ActiveRecord: 2.6ms)
    in my controller
    def partner_rate
    ...
    @rate = "10.00"
    render :json => @rate    # for testing purpose only
    end
    and the alert result is not displayed , what am I missing here ?
    thanks for your feedback
    and this is you PartnerRate method, so I guess you have to do

    $.ajax
    url: " /backoffice/expenses/partner_rate"
    ....
    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Javier Quarite at Mar 26, 2012 at 9:12 pm

    On Mon, Mar 26, 2012 at 3:48 PM, Erwin wrote:

    thanks for your feedback .. maybe so mistake typing this post ,
    however the url is fine , as the action is correctly reached ..
    if I use :
    render :text => @rate
    then the result is displayed ..
    so it's not an Ajax call issue , rather something I don't get right
    with json

    can I use render :json => @ rate

    @rate being a String object ? I tried
    render :json => {:name => "joe"} # i.e example
    and the result is also received back

    so what could be wrong withe render :json => "<String> ???
    well I think you should change that hash {:name=>"joe"}.to_json
    for example today I've done something like this

    @activities = Activity.all

    respond_to do |format|
    format.json { render :json => @activities.to_json(:only=>[:id])}
    end

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 26, '12 at 4:48p
activeMar 26, '12 at 9:12p
posts4
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Javier Quarite: 2 posts Erwin: 2 posts

People

Translate

site design / logo © 2021 Grokbase