Ruby on Rails: Replace a link with javascript - ruby-on-rails

I have this
And I want the link to be replaced with an actual link.
So i figured I use this
page.replace_html("preview_button","<a href='/preview/#{#object.name.to_url}' class='preview' onclick='window.open(this.href);return false;'>Preview</a>")
but when I use the inspecter with chrome, it tell me
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
so... ideas?

The problem there is not your javascript replacing function. That seams to be all right.
You must inspect the link BEFORE you click the link but after the function was called, so you can see if it is being generated right.
The 500 error means that the request reached your rails controller but something wasn't right inside that.

Related

SAPUI5 invalid MIME part type with Remote oDATA Service

I need help showing the data from my own remote server with oDATA.
When I want to show the data in the view, I get the following error
invalid MIME part type.
These are the Captures of Error
my https://******/$metadata?
My Table control from SApui5 Course App example
Error when executing the application
And Console error
When I insert this.getModel().setUseBatch(false) in the init : function () of the Component.js, it does not give me the error, nor in the console, but it does not show me the records either .. Can someone give me an idea?
It's an old question, but recently I've got the same error with batch request processing and in my case the root cause was that when building batch processing response with content type multipart/mixed you have to use CRLF as a text line separator ('\r\n') and not only '\n'. See also here in multipart response specification. The hard part was that correct and incorrect responses look absolutely identical when debugging.

Null exception after calling Post Request

I am building a web api on asp.net. I make requests through client and server. GET and DELETE methods are working properly. When i make POST or PUT i get an error "Response status code does not indicate success: 500 (Internal Server Error)."
Client:
Server:
I used this tutorial.
Why i get a null object (Employee)?
If AddEmployee is an endpoint, then you may need to put the [FromBody] attribute on the parameter.
If it's not an endpoint, then I don't see where AddEmployee is being called. But it looks like the employee parameter is the one that is null. Look up the stack trace, and I bet you'll find someplace where employee is not being set.
I dont know how but when i built a new project the error dissapeared... I used the exact same files and classes.

How to ignore HTTP errors in a iMacros script?

I have 1000+ URLs that I want to scrape to retrieve the title value from the HTML. After trying different things, I ultimately used iMacros scripts, which I don't know anything about. Nonetheless, I managed to make a script after reading guides.
My script is working perfectly but has a problem: When leeching URLs titles, if it encounters an HTTP error (e.g. dead link, forbidden page, etc), it crashes with an error message like this one:
Error -1350: Error loading page. Http status 403. Line 4: URL GOTO=http://url.com
Instead of crashing when the script encounters these errors, I would like it to simply skip the URL and continue running. How can I modify my script to do this? Here is my script:
VERSION BUILD=9002379
TAB T=1
TAB CLOSEALLOTHERS
URL GOTO=http://google.com/
ADD !EXTRACT {{!URLCURRENT}}
TAG POS=1 TYPE=TITLE ATTR=* EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=d:/ FILE=links.txt
SET !EXTRACT_TEST_POPUP NO
Output:
http://google.com/,Google
I would also like to replace the comma after the URL in the output with a semicolon.
At critical points where you don't want to exit at fails:
SET !ERRORIGNORE YES
If you want to revert back at some point to do stop on an error:
SET !ERRORIGNORE NO
You can use these two as many times as you like, even every second row turn on and off.

I got 'Document is empty' when using grape

all
I got the error when using grape.
This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.
in fact, My api works and return the xml well. and after sometime's running , it start to buggy. show that error. my server is nginx + passenger. rails2.3.8. + grape. any help?
The error is from Chrome, displayed when content-type is xml and the xml is not well formed, or in your case as the error indicates, empty. Your api will still work from clients (such as curl) that do not parse and verify the content type.
It's best to hit your api with curl instead of a browser when you encounter something odd.

Grails redirect to a page in case of error

Here is a simple question. Is there any possibility of, if in any case there's an error in an application and the server show us an error page, instead redirect everything to a default page ?
Covering all errors.. is that possible ?
Grails already does this for you. If an exception bubbles up to the container, it gets handled as an HTTP 500 (Internal Server Error). With conf/URLMappings.groovy you can control what happens what happens when error statuses occur.
Here's the default mapping for 500 responses (from conf/URLMappings.groovy):
"500"(view:'/error')
This tells the application to render the error view, which is located in views/error.gsp. If you want to change this, you can. You could redirect to a controller/action if you want:
// will go to 'custom' action of ErrorController, which you would create yourself
"500"(controller: "error", action: "custom")
You can configure this for any HTTP response status. See the URL Mappings documentation. If you need finer control over different exceptions that might be encountered, look at the "Declarative Error Handling" section in the referenced docs above.

Resources