Rails 4 - form with namespace model name spliting route name -


i have rails 4 app admin namespace , model called gametime

namespace :admin   resources :gametimes end 

the model game_time.rb

class gametime < activerecord::base end 

the index , show action work fine. having problem new action.

gametimes_controller.rb

def new   @gametime = gametime.new end 

new.html.erb

<% form_for [:admin, @gametime ] |f| %> <% end %> 

i error

 nomethoderror @ /admin/gametimes/new   undefined method `admin_game_times_path' #<#<class:0xae0d74c>:0xae0c2c0   request parameters   {"action"=>"new", "controller"=>"admin/gametimes"} 

the routes show this

  new_admin_gametime    /admin/gametimes/new(.:format)       admin/gametimes#new 

i don't see why putting path "game_time" rather "gametime" ?

your model named gametime capital "g" , "t". form_for assume route game_time.

if want default route gametime, model should named gametime - ie "g" being capitalized.

internally form_for uses activemodel::name#param_key figure out part of url, illustrates behaviour you're seeing:

gametime.model_name.param_key # => "game_time" gametime.model_name.param_key # => "gametime" 

note how file model named game_time.rb, there consistency there.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -