LonelyWebCrawler
LonelyWebCrawler

Reputation: 2906

Creating a Rails partial that is model-agnostic

I have the two Ruby on Rails models SafetyTest and TeamDue, and want to create a partial called _seasonal.html.erb that can work with either models.

The real problem is adding a link to create a new instance. For example, it would be this code for just SafetyTest:

<%= link_to new_safety_test_path %>   

Now I want to be able to specify in my view, when I'm rendering _seasonal.html.erb, whether I want such a link for SafetyTest or TeamDue . I'm not sure what local to pass to this partial so that it creates the right new link without making a mess.

How should I go about doing this?

Upvotes: 1

Views: 87

Answers (1)

Jiř&#237; Posp&#237;šil
Jiř&#237; Posp&#237;šil

Reputation: 14402

Take a look at Polymorphic URL helpers.

Upvotes: 1

Related Questions