I
I
itemashabanov2018-12-04 20:46:55
Ruby on Rails
itemashabanov, 2018-12-04 20:46:55

How to pass parameter from view "a" to controller "b" Rails?

Hello.
There are three scaffolds: Group, Discipline, Teacher_material. Group has_many Disciplines, Disciplines has_many Teacher_materials. When creating a Discipline, I specify the number of the Group to which it belongs. And in the Group view there is a list of these same Groups, and I want that when I click on the name of the Group, a page opens with the Disciplines belonging to this Group (now a list of all Disciplines opens). How to implement it? 4 days I can not cope. Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
itemashabanov, 2018-12-05
@itemashabanov

Oh God, could I really do it?))) I'm very glad, because for 5 days I could not figure out how to pass the group id as a parameter to the Disciplines controller. But it turns out that in Rails this is very simple (I thought that the controllers were closed to each other, but in fact they are not).
If anyone needs it: in the Group view, I pass the parameter as follows:

<a href="<%= disciplines_path(:group_id => group.group) %>">
  <dt>
    <%= group.group %>
  </dt>
</a>

And in the Disciplines controller I already accept it and pass it as a parameter to the filter
def index
    @g = params[:group_id]
    @disciplines = Discipline.where(group_id: @g)
  end

A
Anton Ivanov, 2018-12-04
@Fly3110

Implement filter in def index of controller Disciplines?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question