RonLugge
RonLugge

Reputation: 5174

How to pass parameters to a view in Rails, e. g. for a search page?

Normally in rails, you pass parameters to views pretty explicitly, by using code like @user = User.find(params[:id]). And then forms can infer their status by using the resulting object, such as form_for @user do ... end.

I'm building a search page that operates on the index. To minimize code writing & duplication between controllers, I'm using the has_scope gem.

So my controller looks like def show @users = apply_scopes(User); end How can I pass the various scopes being applied into the view so I can re-use them in the search fields? My first thought is to make params a helper method, but... that's a code smell. A pretty big one, I'm told.

Upvotes: 1

Views: 332

Answers (1)

smathy
smathy

Reputation: 27961

As per the README:

You can retrieve all the scopes applied in one action with current_scopes method.

Upvotes: 1

Related Questions