Saturday, October 22, 2016

Learning - Shayan Sobhanian

Learn From the Sagebrush
But there is something that grows and keeps on growing in
the Nevada desert—the sagebrush. It couldn’t move away and it
couldn’t change its waterless environment, so it did what you and I
must do if we expect to succeed. It adapted itself to its environment,
and there it stands, each little stalwart shrub a reminder of what
even a plant can do when it tries!

Moving Won’t Help Much

Monday, October 17, 2016

Client Side code Shayan sobhanian-058778888

Client -Side Code

Open app/views/messages/index.html.erb and change the form_for statement to add remote: true, as shown in Listing 6-14.
<%= form_for :message, remote: true do |form| %>
<%= form.text_field :body %>
<%= form.submit 'Send Message' %>
<% end %>
Listing 6-14.Messages Index View changed to a remote form
Now edit the generated messages channel CoffeeScript file, app/assets/javascripts/channels/messages.coffee. As you can see, the default callbacks for connected, disconnected, and received are stubbed out for you. Since we simply want to append any message HTML partials that are received via the channel, simply add the jQuery statement as shown in Listing 6-15.
connected: ->
# Called when the subscription is ready for use on the server
disconnected: ->
# Called when the subscription has been terminated by the server
received: (data) ->
# Called when there's incoming data on the websocket for this
# channel
$('#messages').append(data)

Listing 6-15.The client-side Messages Channel code

Sunday, October 16, 2016

Shayan Sobhanian Json Response-7988855542

Using Rails for API Servers

The Rails API Project

JSON Response Creation

By default, a Rails 5 API-only application just relies on the to_json method of each model to generate the JSON output, but you will likely want to make use of a serialization library such as JBuilder or Active Model Serializers.

Active Model Serializers


Shayan Sobhanian Fixture model class-509884665

Shayan Sobhanian - Fixture Model Class

model_class: User
alan:
name: Alan
This was possible in earlier versions by using set_fixture_class within the test case class itself. However, since this setting is related to the fixture rather than the test case, and having it set in the test case precludes fixtures being properly loaded by the task db:fixtures:load, this fixture’s metadata has been moved into the fixture file itself.

Enum Values

Whereas previously, you would have to know that english is the first enum value, therefore having the value 0, you can now write the fixture as follows:
name: Fred
language: :english

Request via Redirect Deprecation

In Rails 5, the request_via_redirect integration request helper and all of the associated methods for each of the HTTP request methods (such as post_via_redirect) have been removed. This method was most often used to allow you to perform requests such as post_via_redirect or patch_via_redirect, which performed the request and then followed any subsequent redirects. Since that is a reasonably common behavior for web applications after a POST or PATCH request , it is often found in integration tests.

Summary


The deprecation of assert_template and assigns is an indicator of both the thinking of the Rails core team and the direction that the test framework may be headed in. It’s definitely worth considering these changes and how they may affect the way that you design your tests.

Rails 5 essentials Shayan sobhanian

Upgrade to PostgreSQL 9.1 or Later

Devise Gem

Callback Chain Changes

In Rails 5, the preferred method to halt a callback chain is to explicitly call throw(:abort); whereas in previous versions of Rails, you could simply return false from a callback method.

Running Tests

$ rails test

Chapter 2 details most of the changes and additions to the Rails API to help you understand how to update your application.