My URL has start parameter as 2015-06-11T11:34+01:00
URL: /admin?start=2015-06-11T11:34+01:00
start_date = params[:start]
When I try to display start_date, I receive 2015-06-11T11:34 01:00 which has + missing. start_date.to_time displays 2015-06-11 11:34:00 UTC. This means it doesn't matter what I send after + i.e., +01:00 or +05:00.
In my ruby console I correctly receive start_date as 2015-06-11 10:24:00 UTC
Please let me know how to retrieve the value of start parameter without the +01:00 getting ignored.
Get the param value as a string:
start_date = params[:start].to_s
Related
I'm sending moment object in request, but unfortunately the date is changing. For example when I choosed some date and I write to console, the date is ok, but in the request time is few hour early what is change the date.
console: Fri Oct 01 2021 00:00:00 GMT+0200 - ok,
In sent json: "2021-09-30T22:00:00.000Z" - wrong
Why it happens and how to fix it.
I made an ajax request to rails. The URL is:
/learners/-638284588?is_combined_page=true&email=test0221k+staging#tt.com&type=ld"
In the log, I see these entries:
Started GET "/learners/-638284588?is_combined_page=true& email=test0221k+staging#rosettastone.com&type=lcd" for 127.0.0.1 at Fri Feb 23 09:31:56 -0500 2018
Processing by Extranet::LearnersController#show as HTML
Parameters: {"type"=>"ld", "email"=>"test0221k staging#tt.com", "is_combined_page"=>"true", "id"=>"-638284588"}
[WARNING] Audit logging has been enabled for Account
parameter ----------------> {"type"=>"lcd", "email"=>"test0221k staging#tt.com", "controller"=>"extranet/learners", "is_combined_page"=>"true", "action"=>"show", "id"=>"-638284588"} test0221k staging#tt.com
In the URL, the email parameter appears as:
email="test0221k+staging#tt.com"
which has a + sign. But when I read the parameter from params[:email], it is printed as:
"email"=>"test0221k staging#tt.com"
in which the + is replaced by a space.
Why does rails overwrite + with a space?
How can I avoid this "test0221k staging#tt.com" and get "test0221k+staging#tt.com"?
This is defined by the URL specification. Rails is just confirming to that spec.
Parameters need to be encoded before putting them in the URL. The easy way to do this is to call encodeURIComponent() in your JavaScript.
Forms do this encoding for you automatically.
I am trying to update a subtask. More specifically just the due date.
I have tried several things and have failed.
This is what I have tried so far:
Attempt 1:
URL: https://app.asana.com/api/1.0/tasks/
JSON: {"data":{"due_on":"6/18/2017 12:00:00 AM"}}
Error: The remote server returned an error: (400) Bad Request.
Attempt 2: Added a parent id to JSON request
URL: /tasks/
JSON: ParentID is masked for security reasons
{"data":{"due_on":"6/18/2017 12:00:00 AM","parent":{"id":################,"name":null}}}
Error: The remote server returned an error: (400) Bad Request.
attempt 3: using /subtask in URL
URL: /tasks//subtasks/
JSON: {"data":{"due_on":"6/18/2017 12:00:00 AM"}}
ERROR: The remote server returned an error: (404) Not Found
What should be the correct URL to send the JSON request and what should be in the request to modify the subtask due date ?
Any help is greatly appreciated.
Thanks
Viv
Vivek,
The first thing I noticed is that the URL doesn't contain the ID of the task you're trying to update - I'm not sure if this is a copy-paste omission in the question, but if not and the URL you're using doesn't have the ID of the task, we won't know which task you're trying to set the due date for - so that might be one thing you're seeing :)
Additionally, I'd like to verify that you're using the HTTP verb PUT for these requests; you can POST new tasks in Asana, but to change fields on an existing task, we expect a PUT. Since subtasks count as tasks in Asana, this can be done just against https://app.asana.com/api/1.0/tasks/:task_id route
One more thing: setting the due date or due time in Asana are actually 2 separate things - most tasks have their due date set, but in our web app you can choose to add the time when setting the due date. This is represented in our API by the fields due_on for dates and due_at for times. If you just want the due date (inferred by the fact that the time is 12:00 AM) you'll probably want due_on and a string whose format is YYYY-MM-DD (in this case, 2017/06/18). If you want to set the actual time, you can use due_at with an ISO8601 timestamp, such as 2017-06-18T08:00:00Z
Putting it all together, here's a curl request I tested here with "due_at" to keep the time aspect in:
curl --request PUT \
--header "Authorization: Bearer $ASANA_PERSONAL_ACCESS_TOKEN" \
"https://app.asana.com/api/1.0/tasks/$TASK_ID" -d '{
"data": {
"due_at": "2017-06-08T12:00:00Z"
}
}'
Finally, and completely unrelated: do you happen to be the Vivek Patel currently working for Yelp? If so, I used to work with you at Sharpcast - small world! If not, no worries, feel free to ignore!
I'm trying to use active_model_serializers to convert an object to JSON. As per this question, I created a file called config/initializers/serializers.rb with the following code:
puts 'Running serializers.rb.'
ActiveModelSerializers.config.adapter = :json_api
I see Running serializers.rb. when resetting the database, but not when running the Rails console. In the console, when I type UserSerializer.new(User.first).as_json, I get {:id=>1, :name=>"Regular User", :created_at=>Thu, 07 Jul 2016 06:03:46 UTC +00:00, :lists=>[{:id=>1, :title=>"Before Wednesday"}]}, which is clearly not JSON. How do I get the as_json method to actually return JSON?
UserSerializer.new(User.first).to_json
http://apidock.com/rails/Hash/to_json
as far as I can get gowalla auth code response contains both expires_at and expires_in but
expires_at is not valid date string so it throws error while comparing dates
any idea to hack omniauth or gowalla strategy would be very welcome!!!
rails 3.0.9
ruby 1.9.2
comparison of String with Bignum failed
oauth2 (0.5.0) lib/oauth2/access_token.rb:72:in `<'
oauth2 (0.5.0) lib/oauth2/access_token.rb:72:in `expired?'
oa-oauth (0.3.0) lib/omniauth/strategies/oauth2.rb:67:in `callback_phase'
{
"scope":"read",
"expires_at":"Sun, 09 Oct 2011 12:47:37 -0000",
"username":"altuure",
"expires_in":1172767,
"refresh_token":"XX",
"access_token":"XX"
}
Why don't you just use whatever you can. expires_in appears to be an interval, so you can do:
expires_at = Time.now + json["expires_in"].to_i
That said, the date string for expires_at definitely parses in 1.9.2-p290 (using DateTime.parse(str)). There's always DateTime.strptime if you need to parse a date/time string according to a given format.
sorry for delay but I commited the patch to the github you can find the details over here http://github.com/intridea/omniauth/issues/485 –