Questions tagged as 'ruby-on-rails'

2
answers

Adding values from a column with Ruby

Hello, I'm starting out with Ruby On Rails, and I'm making an application that manages expenses. Well what I need to do add up all the expenses of the "value" column and show in the view. I'm trying the following in ActiveRecord def total...
asked by 01.10.2014 / 05:02
1
answer

How to add functionality to a Model that depends on Controller or View

I would like to add the following methods to my Models when presented in the View, such as can_be_showed , can_be_edited , can_be_destroyed , among others, however in some cases these methods may depend on Controller , such as...
asked by 27.01.2015 / 04:31
1
answer

Bring data automatically with Associations

I have two models cliente.rb and atendimento.rb , both already with their associations . When I am going to generate a new service with collection_select select the name of the client, the problem and what I would like at...
asked by 16.10.2014 / 22:01
2
answers

Active Record Rails 4

If I have an Evaluation model and I make avaliacaoes = Avaliacao.all and then avaliacoes.where("score = ?", 3) . In the first command Rails fetches all evaluations, what happens in the second command? Will Rails get the core apprais...
asked by 26.08.2014 / 21:32
1
answer

How to get related data in Ruby on Rails?

Hello. I have an application where User has_many Status . And Status has_many Likes . How do I get the total likes a user has? For example, it has 2 statuses with 10 likes each, which gives a total of 20 likes. How d...
asked by 20.08.2014 / 00:52
1
answer

Problem running test controller in rails 4

Good afternoon, I generated a scaffold of a class of mine, example User. When running the tests I came across the following failure: Minitest::Assertion: "User.count" didn't change by 1. Expected: 3 Actual: 2 test/controllers/users_contr...
asked by 30.07.2014 / 21:59
1
answer

Relationship has_and_belongs_to_many Rails 4

I have an Item has_and_belongs_to_many template: gender and a Gender template has_and_belongs_to_many : items, also a relationship table generos_itens (id_item, genero_id). I'm trying to create a new relationship between item and gende...
asked by 19.05.2014 / 21:11
1
answer

activerecord is not saving the relationship

I have such a relationship in rails class ReducaoZ < ActiveRecord::Base self.table_name = 'reducaoz' has_many :aliquotas, foreign_key: 'reducaoz_id', class_name: 'Aliquota', dependent: :delete_all end class Aliquota < ActiveReco...
asked by 22.05.2014 / 16:11
1
answer

Validating a template with scope in Ruby on Rails

Suppose the models: class A < ActiveRecord::Base has_many :bs end class B < ActiveRecord::Base belongs_to :a has_many :cs end class C < ActiveRecord::Base belongs_to :b end If I want a C attribute to be unique in B's scop...
asked by 12.05.2014 / 14:27
1
answer

Display error message correctly

I have this code: flash[:error] = t("errors.messages.restrict_dependent_destroy.many") and the system displays the following error message:    Can not delete the record because there are % {record} dependents I want it to show this...
asked by 13.05.2014 / 14:09