1

I have a 'media' model, and the controller through which I am doing any changes to that table is called 'MultimediaController'.

When creating a new media and trying to redirect, I get the following error: undefined method 'medium_url' for #<MultimediaController:0x007f86f49ca400>

I dont have any tables, models, controllers or anything else called "medium". I'm assuming rails is doing this automatically based on my table named 'media'. Is there any way I can overwrite this?

edit: my redirect looks like this: respond_with(@media, {:controller => 'multimedia', :action => 'index', :id => session[:user_id], :collection => @media.collection_id})

fridgerator
  • 323
  • 7
  • 17

2 Answers2

1

"Media" is plural for "medium" so it sounds like you've got some renaming to do or customizations in inflections.rb.

miked
  • 4,489
  • 1
  • 17
  • 18
  • happy to help. It might be as simple as adding an inflect.irregular 'media', "medias" in the block in inflections.rb. But of course, it's still not grammatically correct. Good luck. – miked Mar 12 '12 at 03:32
0

Medium_url would mean rails is looking for a single "Medium" record (or whatever database you are dealing with .. media etc). You'd have to pass in an id in order to redirect to the Medium object when using medium_url.

If you want to redirect to a list of all Mediums (Your index action) you should be using mediums_url.

Rails has a fantastic guide on restful routing.

http://guides.rubyonrails.org/routing.html

def create

  # Code to create the record goes here blah blah.

  # Redirect to a list of all mediums
  redirect_to mediums_url

  # Or redirect to the medium object we just created
  # redirect_to medium_url(@object)
end
James
  • 2,284
  • 1
  • 20
  • 29
  • But where is 'medium_url' coming from? I'm not using 'medium' anywhere in my application. Is it coming from Media? my console out put from 'media'.pluralize is "media", and 'medias'.singularize is "media". – fridgerator Mar 12 '12 at 01:30
  • Do you have a route in routes.rb called resources :mediums ? – James Mar 12 '12 at 09:54