Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7610357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:23:56+00:00 2026-05-31T01:23:56+00:00

ruby 1.9.2p290 rails 3.1.1 Basically I have two models: CHEFS and RECIPES. class Chef

  • 0
  • ruby 1.9.2p290
  • rails 3.1.1

Basically I have two models: CHEFS and RECIPES.

class Chef < ActiveRecord::Base 
 has_many :recipes
end

class Recipe < ActiveRecord::Base
 belongs_to :chef
end

And the following routes:

resources :recipes

resources :chefs do
 # list of recipes from chef
 resources :recipes, :to => 'recipes#index_chef'
end

With this I have the urls (exactly what I want):

  • /recipes – list of recipes
  • /chefs/username/recipes – list of chef’s recipes
  • /chefs/ – list of chefs
  • /chefs/username – chef’s profile

RecipesController:

def index
 @chef = Chef.find_by_username(params[:chef_id])
 @recipes = Recipe.where({ :status_id => 1 }).order("id desc").page(params[:page]).per(9)
end

def index_chef
  @chef = Chef.find_by_username(params[:chef_id])
  @recipes = @chef.recipes.where(:status_id => 1).order("id desc").page(params[:page]).per(9)
end

My recipes index view:

<%= link_to recipe.chef.username.capitalize, @chef %>

In http://3001/chefs/username/recipes I have the correct link to Chef profile.

But in http://3001/recipes I have the wrong link.

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:23:57+00:00Added an answer on May 31, 2026 at 1:23 am

    In http://3001/recipes (which is a weird url!), you don’t have access to params[:chef_id]. So you won’t have the @chef variable available to you in the view. It should be nil!

    To get around this, change your link_to to this

    <%= link_to recipe.chef.username.capitalize, recipe.chef %>
    

    You might want to eager load the chef to your @recipes records by loading that in your controller like this:

     @recipes = Recipe.where({ :status_id => 1 }).includes(:chef).order("id desc").page(params[:page]).per(9)
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ruby 1.9.2p290 rails 3.1.1 I have two models: RECIPE and RECIPE_CATEGORY with belongs_to and
My environment: Ruby 1.9.2p290, Rails 3.0.9 and RubyGem 1.8.8 unfortunately I have an issue
Somehow my rails installation hides itself successfully... I have: ruby 1.9.2p290 (2011-07-09 revision 32553)
Ruby has two different exceptions mechanisms: Throw/Catch and Raise/Rescue. Why do we have two?
Ruby on Rails does not do multithreaded request-responses very well, or at least, ActiveRecord
Ruby on Rails controllers will automatically convert parameters to an array if they have
I have an app based on Rails 3 (version Rails 3.1.2 ) and ruby
I am running Rails 3.0.1 with Ruby 1.9.2p290.In rails c Time.zone gives => (GMT+00:00)
I am running Ruby on Rails 3.2.2 from 3.1.0. I have the issue undefined
I'm running Ruby 1.9.2p290 and Rails 3.1.0.rc5. When I run this regex it matches

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.