Rails 'Parse_Query' Error on Server in Brand New App

Rails 'parse_query' error on server in brand new app

I was getting the same thing, but with Rails 4.2.1, and running on Puma 2.11.3.

I noticed that Bundler just upgraded rack to 1.6.3. Setting the version back to 1.6.2 resolved it for me.

Get query string from extract URL if exists

The keys in query string in a URL can be accessed using params[] hash, even if the URL is not present inside the app itself. This is how it is convenient for rails to communicate with the outside world as well. Note that rails treats all the HTTP verbs equally when it comes to usage of params[] hash.

Usage: puts params[:your_key]

Parser error when using jQuery-UJS for remote link_to in Rails 3 app: how can I debug this?

I'm going to propose an answer because comments don't allow for any formatting. Here is is: Something is happening on the server side and jQuery is not getting what you think it is. Here's an excerpt from the jQuery documentation:

error(jqXHR, textStatus,
errorThrown)Function A function to be
called if the request fails. The
function receives three arguments: The
jqXHR (in jQuery 1.4.x,
XMLHttpRequest) object, a string
describing the type of error that
occurred and an optional exception
object, if one occurred. Possible
values for the second argument
(besides null) are "timeout", "error",
"abort", and "parsererror". When an
HTTP error occurs, errorThrown
receives the textual portion of the
HTTP status, such as "Not Found" or
"Internal Server Error."

That implies that your controller may be responding with something other than the expected data. In that controller, try:

Rails.logger.debug render_to_string(:partial => "followings/follow")

In any case, check your logs to make sure what you think is happening really is happening. Also, write a test to verify this:

# controller spec... modify if using Test::Unit
it "sends cool javascript" do
xhr.post :unfollow, :id => 83, :data-method => "delete"
response.body should == "some known response"
end

Ok, it's a hacky, brittle spec, but it will do until you know where things are going wrong.

Once you get this working, everything else will fall neatly into place.

Strange Timeout::Error with render_to_string and HTTParty in Controller Action

Common problem, but hard to track if too close to monitor.

I guess you run rails server which normally starts one single WEBrick server process.

Unfortunately you will block yourself while local testing.

Fix: Start another rails server with different port number. Or start something like unicorn and set worker number to 2 or more.

Rails An Error Occured While Parsing Params

Since you have:

params.require(:choice).permit(:appuser_id, :answer_id, :question_id)

choice is required and you should be passing your JSON like this:

curl -v -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST -d '{"choice": {"question_id":"1", "answer_id":"2"}}' http://ec2-54-186-132-102.us-west-2.compute.amazonaws.com:8080/questions/1/choices

Ruby on Rails where query with relations and updated_at compare

You fetching projects.updated_at, but if I understood you right you need to fetch reasons.updated_at

reasons = reasons.joins(:project).where("reasons.updated_at > ?", DateTime.parse(updated_at))

produses that output for me

GET http://localhost:3000/reasons/index?updated_at=2016-05-04T06:43:19.280Z

[
{
"id": 2,
"name": "R2",
"project_id": 3,
"created_at": "2016-05-04T06:43:19.280Z",
"updated_at": "2016-05-04T06:43:19.280Z",
"deleted": false
},
{
"id": 3,
"name": "R3",
"project_id": 3,
"created_at": "2016-05-04T06:43:25.895Z",
"updated_at": "2016-05-04T06:43:25.895Z",
"deleted": false
}
]

And without any filter

GET http://localhost:3000/reasons/index

[
{
"id": 1,
"name": "R1",
"project_id": 3,
"created_at": "2016-05-04T06:43:11.044Z",
"updated_at": "2016-05-04T06:43:11.044Z",
"deleted": false
},
{
"id": 2,
"name": "R2",
"project_id": 3,
"created_at": "2016-05-04T06:43:19.280Z",
"updated_at": "2016-05-04T06:43:19.280Z",
"deleted": false
},
{
"id": 3,
"name": "R3",
"project_id": 3,
"created_at": "2016-05-04T06:43:25.895Z",
"updated_at": "2016-05-04T06:43:25.895Z",
"deleted": false
}
]

Posting to Ruby on Rails app from android

You're setting a content-type of JSON but not actually sending JSON, you're sending standard POST url-encoded parameters.

You need to actually send a JSON object:

JSONObject params = new JSONObject();
params.put("drinks_id", GlobalDrinkSelected);
params.put("name", GlobalEditTextInputName);
params.put("paid", GlobalIsPaid);

StringEntity entity = new StringEntity(params.toString());
httpPost.setEntity(entity);


Related Topics



Leave a reply



Submit