A
A
Andrey Demidenko2015-02-10 02:57:22
Ruby on Rails
Andrey Demidenko, 2015-02-10 02:57:22

Is it possible in rails to call a view with a parameter?

There are many identical tags, but for different objects. Is it possible somehow to use one view by simply passing the desired object there

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Vsk, 2015-02-10
@Dem1

Certainly. See what locals are: guides.rubyonrails.org/layouts_and_rendering.html

# controllers/users_controller.rb
@user = User.find(params[:id])
render 'shared/profile', resource: @user

It will take the views/shared/_profile file and the resource variable will appear in it:
# views/shared/_profile.html.erb
resource.name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question