Mittwoch, 28. August 2013

Authorization with CanCan

I continued refactoring Voluntary to replace user by polymorphic resource association for vacancy and candidature models and got blocked when I tried to prove the refactoring in development mode so I had to wait for Mathias.

Meanwhile I continued working on my small application translate_german_words. It was about refactoring the part that saves the translation in a file. I only have one error and then this part is finished.

As Mathias arrived we found and handled the error source in a hidden authorization logic issue caused by the refactoring.
At this opportunity he explained to me the authorization solution CanCan
We finished the refactoring and proved the integration of it by tests.

Positive things of the day:
  • Ran in circles with the block in Voluntary, but now I know much better the application
  • Can see the importance of having tests. I don't have tests for my small application and I think the changes could be easier with the tests.




Dienstag, 27. August 2013

Tagging with Acts-as-Taggable-on

I have dedicated part of the day to learn about Tagging. I have used the gem Acts-as-Taggable-on in the project learning app. However, I didn't make the Tagging from Scratch.

Then, I continued refactoring my small application (translate_german_words). Another consequence of using meaningful names in your code is that you can see easily, where there is repetition in your code.

Bye!


Montag, 26. August 2013

Geocoder, clean code and refactoring

I've been learning Geocoder with Railscasts. We will need this gem for a story in the future. Also, I'll need to learn Google-Maps-for-Rails, but we'll have to investigate which free map can we use.

After that, I have read Clean Code (Use Intention-Revealing Names) and started to apply that in a small application (translate_german_words) that I wrote for translating a list of german words to spanish. It's difficult to give good names but I can see the results. When you read the code it's like you are reading a story.

I learned a pair of useful commands of git:
- To delete a lot of files that appear as deleted files in git status:
git rm $(git ls-files --deleted)

- To delete a file with Umlaut (for example: abhängig)
git rm $'third_version/first_traduction/GermanWordsTranslation_abha\314\210ngig_ADJ.ods'

After that, I worked in Voluntary. My task is refactoring the code to change from user_id to resource_id and resource_type. However I got blocked because I tried to test the application from voluntary_classified_advertising, and this application don't see the changes in Candidature table.
Tomorrow, I'll continue with Voluntary.

Bye!!





Freitag, 23. August 2013

A Roadblock and polymorphic Associations

To complete the current story about requesting all types of resources (e.g. human or material assets) as a project owner Mathias had to resolve a roadblock and implemented a own variant of accepts_nested_attributes_for magic for nested forms with different database systems (PostgreSQL and MongoDB).

After a break and joining interesting workshops and talks at Eurucamp we started the next story about responding resources as a crowd worker and so allocate a resource to a vacancy through a candidatures "casting".

In preparation of the story I followed the nested model form screencast and Mathias showed me how to override the wizard of the workspace in our new product voluntary_classified_advertising using the example of a new feature about replacing the core task result form by a resources form.

As the first task of the story I am refactoring the core vacancy and candidature to belong to a polymorphic resource (asset or user) instead of only an user and try to complete this task as a homework.


We'll review the homework at our next meet up at Travis office on Wednesday and start the next task about a new (material) model with the working title "asset" for the candidature's and vacancy's polymorphic resource association.

Have a nice weekend!

Dienstag, 13. August 2013

Wicked and Redcarpet

Today I have learned Wicked with the Railscast for Wicked. For overriding the redirect_to_finish_wizard method, you should use a parameter.

def redirect_to_finish_wizard(options = nil)
    redirect_to root_path , notice: "Thank you for signing up."

end

Then I used Redcarpet. The code for Redcarpet in Railscast for Draper don't work with my code (perhaps different versions), so I followed the documentation in Gem Redcarpet.

Today has been an easy day.

Montag, 12. August 2013

Remember and Reset Password and use of Draper

Today I have continued Remember and Reset Password. I achieved reset the password and the remember password in Sign Up and Log In pages. (The problem No route matches [PUT] "/password_resets.tyubOZQQExHjqqOSfMRqAw" was a silly typo error)

Also, very interesting. I use simple_for for the log_in form (I am not using an object for the model for the form, instead I am using the symbol :log_in)

<%= simple_form_for :log_in, { url: sessions_path } do |f| %>
  <%= f.input :email %>
  <%= f.input :password %>
  <%= f.input :remember_me, as: :boolean, input_html: { checked: true } %>
  <p><%= link_to "forgotten password?", new_password_reset_path %></p>
  <%= f.button :submit, "Log in" %>
<% end %>

So, to use the params in the controller I needed to use params[:log_in]. An example:

user = User.authenticate(params[:log_in][:email], params[:log_in][:password])

After that, I followed the steps in Draper railscasts. I think that the version in the Railscasts is older than the one I used, because I had to make some changes.

Finally, I pushed every change in the repository.

Good night!!






Donnerstag, 8. August 2013

New product for voluntary

Today, we finished the creation of the new product voluntary_classified_advertising following the steps for creating a new voluntary product (engine). We created the model and data for this new model. Also, we talked about the briefing for the following stories in our backlog.

I learned a very interesting feature: The product has inside an engine for testing (called dummy), which can be used as a server, so we don't need an external application where voluntary and the products run.

Bye!!







Montag, 5. August 2013

Underused features of ActiveRecord

Today, we have finished the story of adding an areas filter for projects in the worker scope.

To paginate database results, voluntary uses the gem will_paginate. As we needed a pagination for a mongodb collection, we figured out that the last release is not compatible with mongoid.
But we found this unreleased feature which supports it, so we now temporarily have to use the edge version of the gem.

While refactoring Mathias showed me one of the underused features of ActiveRecord: scope merging.

At the end of the day I started a new story about creating a new product voluntary_classified_advertising following the steps for creating a new voluntary product (engine).

Tomorrow we will extend the core task through the new product to support vacancy allocation.

More things tomorrow!!!


Freitag, 2. August 2013

Refactoring & Patterns

Today, Mathias amplifies some previous lessons and the crowdsourcing vision needed to complete the story like refactoring, (design) patterns, routing, blocks and the engine to recommend proper work for the crowd.

Especially the refactoring of the routes file to use this gist and distribute concerns to separate route files was very interesting to me.

This prevents us from completing the story today but it was good to immerse myself in the software engineering principles and be more confident to live them in the future.

Have a nice weekend!

Donnerstag, 1. August 2013

Remember Me & Reset Password

In http://disaster-assistance.blogspot.com/2013/07/how-i-test.html, I followed the railscast http://railscasts.com/episodes/275-how-i-test.  Although I passed every test, my project_learning_app wasn't able to send a mail.

To solve the problem, instead of test environment, I used the development environment. So I used the following configuration in config/environments/development.rb, and it worked:

  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default_url_options = { host: "localhost:3000" }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'localhost:3000',
    user_name:          'user@gmail.com',
    password:             'password',
    authentication:       'plain',
    enable_starttls_auto: true  }

But, I had an error because I should complete the edit and update method of password_resets_controller.rb, so I followed another railscast: http://railscasts.com/episodes/274-remember-me-reset-password?view=asciicast
This railscast was interesting:
- First, the railscast use form_for and I use simple_for, so for the check_box in simpleform, I used:
<%= f.input :remember_me, as: :boolean, input_html: { checked: true } %>

- At the moment, I obtain the following error when I try to change the password:
No route matches [PUT] "/password_resets.tyubOZQQExHjqqOSfMRqAw"

Well, I'll continue with this interesting question another day.

Have a good weekend!!!