Answer the question
In order to leave comments, you need to log in
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
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>
def index
@g = params[:group_id]
@disciplines = Discipline.where(group_id: @g)
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question