Eduardo Pedroso
Eduardo Pedroso

Reputation: 879

Rails Redirect_to not rendering the view

I'm trying to load a view after some actions in my controller, I'm getting the message that the view was loaded, but the view is never showed

My Controller:

def getBalance
 @result
 accountId = params['accountId']
 baseURLUpdate = 'http://xxxxxxxxxx' + accountId + '/statement'
 transactionHash = generateTransactionHash(accountId)
 @result = HTTParty.get(baseURLUpdate.to_str,
 :headers => { 'Content-Type' => 'application/json',
              'Api-Access-Key' => 'xxxxxxxx',
              'Transaction-Hash' => transactionHash } )

 puts @result
 redirect_to accounts_response_path(:result => @result)
 return
end

My routes:

post 'accounts/getBalance', to: "accounts#getBalance"
get 'accounts/response', to: "accounts#responseShow"

My view is called responseShow.html.erb, and I do have a response.html.erb too.

I'm getting this:

Redirected to http://localhost:3000/accounts/response.html
Completed 302 Found in 409ms (ActiveRecord: 0.0ms)


Started GET "/accounts/response.html" for 127.0.0.1 at 2016-01-19 10:36:02 -0200
Processing by AccountsController#response_show as HTML
I'm here
Rendered accounts/response_show.html.erb within layouts/application (0.0ms)
Completed 200 OK in 18ms (Views: 17.2ms | ActiveRecord: 0.0ms)

Upvotes: 0

Views: 1737

Answers (1)

You can try with format block in your controller:

respond_to do |format|
 format.html {redirect_to accounts_response_path(:result => @result)}
 format.js   {render :js => "window.location.href='"+accounts_response_path(:result => @result)+"'"}
end

Upvotes: 3

Related Questions