0
I am working on a Ruby on Rails project and I am working on a module (Financial) it is linked to several models, and depending on the screen that the user is he can bring a screen with all the financial movements of that object. However I wanted to do only a partial, in partial I would pass a variable (catch via metaprogramming) to a given field (also caught via meta programming)
To try to generate the link I am doing so:
<%%= link_to new_financial_path(<%= singular_table_name %>_id: @<%= singular_table_name %>.id), class: 'btn btn-primary pull-right', remote: true do %>
<span class="fa fa-plus"></span>
<%= I18n.t('financials.new.new') %>
<%% end %>
But the system is returning
NoMethodError - undefined method `singular_table_name' for #<#<Class:0x007ff098434898>:0x007ff0b5c02eb8>
Did you Mean? singleton_method: app/views/Financials/_Financials.html.erb:2:in `_app_views_financials__financials_html_erb___3468020359035041149_70335661148700'
Does anyone know how I could do it? After all it would be much easier since the only thing that changes is the colum_id field: @columvariable_id in case Colum would receive the singular table name of the controller itself.
If I do so <%= link_to new_financial_path(<%= controller_name.singularize %>_id: @<%= controller_name.singularize %>.id), class: 'btn btn-Primary pull-right', remote: true of %> <class="fa fa-plus"></span> <%= I18n.t('Financialsnew.new') %> <%% end %> The system prints an html line like this: <%= link_to new_financial_path(<%= controller_name.singularize %>_id: @Reproduction.id), class: btn btn-Primary pull-right', remote: true do %> <%= I18n.t('Financials.new.new') %> <% end %>
– André Gava
You are aware of this error because there is no "singular_table_name".
– Magno Costa