How do I preselect a reference to a resource that is not a parent in the routes?
I have an app with a ContentCategory model that has_many :contents. In the ContentCategoriesController#show view there is a button for "New Content". This goes to the ContentsController#new view which has a select box for the content_category. Currently this defaults to the first category in the list instead of the desired behavior of defaulting to the ContentCategory of the page before. Is there a way to achieve this without nesting the resources in routes.rb?
Hey Joel,
Is the name of the category in the url of the previous page?
If so, then
Is the name of the category in the url of the previous page?
If so, then
request.referrer
will give you the url of the page that sent you there.
Otherwise, you can just pass it as a param that would appear at the end of your url ?cat=meow