ruby on rails - rendered page completely changes, after adding a call to `render` -


i have in controller;

  def get_response     response = httparty.get('url')     render json: response.to_json   end    def edit     @newevent = event.find(params[:id])      json = get_response      byebug   end 

now when go edit page, shows json response, not want.

i want response usable via edit page. call response. id (currently isn't working, said, can json , show, removed edit page, not want want json used inside edit page)

after rereading several times, think understand problem.

what happened

i think confusing rails magic™, handy , yet makes super hard beginners make step using rails generated code own versions , understand why stuff breaks.

a controller action empty edit was, implicit render <name-of-controller-action>. write actual render yourself, rails not implicit render. did 'overwrite' rails one. yielding result of seeing json rendered , not edit page anymore.

how solve it

what trying adding content edit view (that first other webpage). using render on several levels wrong approach. (i suggest rereading rails guides, since think concepts not yet clear you).

what want building upon existing edit view (edit.html.erb). want add content somewhere in view , of course need prepare in controller view can access it.

so in controller might along lines of @website_content = httparty.get('url') meaning in view can use @website_content display json downloaded.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -