Mostrando las entradas con la etiqueta rails. Mostrar todas las entradas
Mostrando las entradas con la etiqueta rails. Mostrar todas las entradas

20150828

one more time with RoR

Today I'm interesting again for testing some of the RoR gems that I was reading and researching a long time ago, but combined all together.

  • rails_admin
  • devise
  • cancan
  • papertrail
Just to become a nice and easy start up app within a few seconds.

First I added the necessary gems to the Gemfile:

As I was using openshift, I had to get rid of the pg (not used, I'm using mysql || sqlite3).

Then:

rails g rails_admin:install


(mounting admin as /admin, the default option)
Then for devise:
rails generate devise:install
rails g devise:views
rails g devise User

For CanCan:
rails g cancan:ability


And for PaperTrail:
rails generate paper_trail:install --with-changes --with-associations

After that, only last to add the ":username" to the User model

rails g migration AddUsernameToUser username:string

Then the usual
bundle exec rake db:migrate

And for the groups, if needed:
rails g model Role name:string
rails g migration addRoleIdToUser role:references
rake db:migrate

And the base is quite OK

20141125

kind of ToDo for my recipe site

For a long time I have a site that I made for recipes. Now, I got a module to handle in the way that I want, the uses, it's called device.

Now, in my internal ToDo, I only have to improve the import of the recipes (avoid having lines with ------~, etc). And is going to be my beta1 (after so many years).

After being in beta for some time, testing all the soft. I'm going to add the "make a buying list", that is quite simple, just an array associated to the user, that contains all the recipes selected by the user, when the user wants to see the list, is generated. All recipes are summed (quantities). for this, I have to have a list of different names for the same ingredient  (like flour, flour 000 and flour 0000 are not the same, but general cooking flour is quite the same as flour 000). And also, the measurement in the different types. But it's going to be a nice improvement to my site.

Also, I have to improve the related article, so it can use tags (or title as a tag), and perhaps have a table to avoid consulting the DB too much; of related articles to related recipes. And have it shown only in the recipe view as a box like:
Or maybe floating on the bottom of the page. I have to test some ideas and view the best way to see the "related articles" in the recipe.



20140409

limit tag cloud with acts_as_taggable_on

Now that I'm having around 300 recipes (just testing recipes, the final count would be more than 10k), I was having some issues with the tags. The tag list was quite big and each new tag was added to the tag cloud.

So I searched for any nice solution, but all was quite messy. The solution was really simple.

To limit the tag-cloud, having something like:



  <% tag_cloud(Model.tag_counts, %w[s m l]) do |tag, css_class| %>
    <%= link_to tag.name, tag_path(tag.name), class: css_class %>
  <% end %>


The solution is something like:


  <% tag_cloud(Model.tag_counts.limit(30), %w[s m l]) do |tag, css_class| %>
    <%= link_to tag.name, tag_path(tag.name), class: css_class %>
  <% end %>

But almost all the solutions on the web makes changes in the controller, models and so on, but almost all that solutions adds more things than the simple answer to the problem

20100302

ruby on rails and reorder the columns order in the view

This year was quite difficult to me, as I don't have a job since the 4th of January until now (2nd of March). And I think that is going to be like that for a some more time (as the interesting projects that I was offered to work in, the money is not enough, but that projects are really cool).

Well, this weekend I tried to keep going into my cook book, now in ruby, as the previous version in Perl was quite nice, but nobody would take that serious, as I did everything by myself and with my own XML definitions. The model that now I'm working is quite easy, a simple database:



ActiveRecord::Schema.define(:version => 20100302024114) do

create_table "categories", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "ingredients", :force => true do |t|
t.string "name"
t.integer "recipe_id"
t.integer "quantity"
t.string "measure"
t.string "part"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "notes", :force => true do |t|
t.integer "recipe_id"
t.string "keyword"
t.text "text"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "recipes", :force => true do |t|
t.string "name"
t.integer "yield"
t.integer "category_id"
t.text "preparation"
t.datetime "created_at"
t.datetime "updated_at"
end

end



This is quite simple, but yet powerful enough to what I need. For example, if i ever need something like the origin of the recipe, I just could add a note titled "origin" and the region in the text field. The only problem and that I should reconsider in some time, is that some preparations have parts, for example the base, the filling and the cover (for example a lemon pie). I manage to put that in the ingredients, as some parts uses the same ingredients, but in different measures, and perhaps somebody just want to make only the filling or the cover, but not the whole meal. But having another table for the preparation, just I don't like for now (as the preparations could vary from 1 to 5 or more, that should be in a separated table).

The main problem that I had was that the documentation was quite nasty about the reorder of the columns. Every web that I found was telling how to reorder the rows (the information in the columns) by an specified column. But I want to reorder the column, and the formal documentation just don't say anything useful to me.

So, after digging a lot of time in Google, I found http://api.rubyonrails.org/ and inside that http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002294 That was the beginning of the solution.

I printed that method, the code was:

class RecipesController < ApplicationController

active_scaffold :recipe do |config|
p config.columns()
end

end


That was quite useful, the very first line of the output was:


Completed in 301ms (View: 26, DB: 0) | 200 OK [http://10.0.0.52/recipes/new?_method=get&adapter=_list_inline_adapter]
#<ActiveScaffold::DataStructures::Columns:0x7fa930f14100 @_inheritable=[:name, :yield, :category, :ingredients, :preparation, :notes],
[...]


For the first time I had the proper names to call the others tables and my recipe table without the default order.


config.columns = [:name, :yield, :category, :ingredients, :preparation, :notes]


I know that this post was quite long and in this nasty language, but most of the people (well, programmers) just search the things in English.