My new.html.erb:
<h1>New konkurrancer</h1>
<%= simple_form_for [:admin, @konkurrancer] do |f| %
<%= f.input :name %>
<%= f.button :submit %>
<% end %>
<%= link_to 'Back', admin_konkurrancers_path %>
And I get this error in view(http://localhost:3000/admin/konkurrancers/new):
Psych::SyntaxError in Admin/konkurrancers#new
Showing C:/Rails/konkurranceportalen/app/views/admin/konkurrancers/new.html.erb where line #4 raised:
couldn't parse YAML at line 20 column 14
Extracted source (around line #4):
1: <h1>New konkurrancer</h1>
2:
3: <%= simple_form_for [:admin, @konkurrancer] do |f| %>
4: <%= f.input :name %>
5: <%= f.button :submit %>
6: <% end %>
See full trace here http://pastie.org/1652928
My controller:
class Admin::KonkurrancersController < Admin::AdminController
# GET /konkurrancers
# GET /konkurrancers.xml
def index
@konkurrancers = Konkurrancer.all
@konkurrancer = Konkurrancer.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @konkurrancers }
end
end
# GET /konkurrancers/1
# GET /konkurrancers/1.xml
def show
@konkurrancer = Konkurrancer.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @konkurrancer }
end
end
# GET /konkurrancers/new
# GET /konkurrancers/new.xml
def new
@konkurrancer = Konkurrancer.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @konkurrancer }
end
end
def statistik
@reklamers = Reklamer.find(:all)
end
# GET /konkurrancers/1/edit
def edit
@konkurrance = Konkurrancer.find(params[:id])
end
# POST /konkurrancers
# POST /konkurrancers.xml
def create
@konkurrancer = Konkurrancer.new(params[:konkurrancer])
respond_to do |format|
if @konkurrancer.save
format.html { redirect_to(@konkurrancer, :notice => 'Konkurrancer was successfully created.') }
format.xml { render :xml => @konkurrancer, :status => :created, :location => @konkurrancer }
else
format.html { render :action => "new" }
format.xml { render :xml => @konkurrancer.errors, :status => :unprocessable_entity }
end
end
end
# PUT /konkurrancers/1
# PUT /konkurrancers/1.xml
def update
@konkurrancer = Konkurrancer.find(params[:id])
respond_to do |format|
if @konkurrancer.update_attributes(params[:konkurrancer])
format.html { redirect_to(@konkurrancer, :notice => 'Konkurrancer was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @konkurrancer.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /konkurrancers/1
# DELETE /konkurrancers/1.xml
def destroy
@konkurrancer = Konkurrancer.find(params[:id])
@konkurrancer.destroy
respond_to do |format|
format.html { redirect_to(admin_konkurrancers_path) }
format.xml { head :ok }
end
end
end
In view I get following error:
NoMethodError in Admin/konkurrancers#new
Showing C:/Rails/konkurranceportalen/app/views/admin/konkurrancers/new.html.erb where line #3 raised:
undefined method `konkurrancers_path' for #<#<Class:0x3e1ae48>:0x3e16270>
Extracted source (around line #3):
1: <h1>New konkurrancer</h1>
2:
3: <%= simple_form_for(@konkurrancer) do |f| %>
4:
5: <%= f.input :name %>
6: <%= f.button :submit %>
Rails.root: C:/Rails/konkurranceportalen
Rake routes:
C:\Rails\konkurranceportalen>rake routes
(in C:/Rails/konkurranceportalen)
admin_kategoris GET /admin/kategoris(.:format) {:action=
>"index", :controller=>"admin/kategoris"}
POST /admin/kategoris(.:format) {:action=
>"create", :controller=>"admin/kategoris"}
new_admin_kategori GET /admin/kategoris/new(.:format) {:action=
>"new", :controller=>"admin/kategoris"}
edit_admin_kategori GET /admin/kategoris/:id/edit(.:format) {:action=
>"edit", :controller=>"admin/kategoris"}
admin_kategori GET /admin/kategoris/:id(.:format) {:action=
>"show", :controller=>"admin/kategoris"}
PUT /admin/kategoris/:id(.:format) {:action=
>"update", :controller=>"admin/kategoris"}
DELETE /admin/kategoris/:id(.:format) {:action=
>"destroy", :controller=>"admin/kategoris"}
admin_konkurrancers GET /admin/konkurrancers(.:format) {:action=
>"index", :controller=>"admin/konkurrancers"}
POST /admin/konkurrancers(.:format) {:action=
>"create", :controller=>"admin/konkurrancers"}
new_admin_konkurrancer GET /admin/konkurrancers/new(.:format) {:action=
>"new", :controller=>"admin/konkurrancers"}
edit_admin_konkurrancer GET /admin/konkurrancers/:id/edit(.:format) {:action=
>"edit", :controller=>"admin/konkurrancers"}
admin_konkurrancer GET /admin/konkurrancers/:id(.:format) {:action=
>"show", :controller=>"admin/konkurrancers"}
PUT /admin/konkurrancers/:id(.:format) {:action=
>"update", :controlle开发者_运维技巧r=>"admin/konkurrancers"}
DELETE /admin/konkurrancers/:id(.:format) {:action=
>"destroy", :controller=>"admin/konkurrancers"}
admin_reklamers GET /admin/reklamers(.:format) {:action=
>"index", :controller=>"admin/reklamers"}
POST /admin/reklamers(.:format) {:action=
>"create", :controller=>"admin/reklamers"}
new_admin_reklamer GET /admin/reklamers/new(.:format) {:action=
>"new", :controller=>"admin/reklamers"}
edit_admin_reklamer GET /admin/reklamers/:id/edit(.:format) {:action=
>"edit", :controller=>"admin/reklamers"}
admin_reklamer GET /admin/reklamers/:id(.:format) {:action=
>"show", :controller=>"admin/reklamers"}
PUT /admin/reklamers/:id(.:format) {:action=
>"update", :controller=>"admin/reklamers"}
DELETE /admin/reklamers/:id(.:format) {:action=
>"destroy", :controller=>"admin/reklamers"}
reklamers GET /reklamers(.:format) {:action=
>"index", :controller=>"reklamers"}
POST /reklamers(.:format) {:action=
>"create", :controller=>"reklamers"}
new_reklamer GET /reklamers/new(.:format) {:action=
>"new", :controller=>"reklamers"}
edit_reklamer GET /reklamers/:id/edit(.:format) {:action=
>"edit", :controller=>"reklamers"}
reklamer GET /reklamers/:id(.:format) {:action=
>"show", :controller=>"reklamers"}
PUT /reklamers/:id(.:format) {:action=
>"update", :controller=>"reklamers"}
DELETE /reklamers/:id(.:format) {:action=
>"destroy", :controller=>"reklamers"}
konkurrencer_index GET /konkurrencer(.:format) {:action=
>"index", :controller=>"konkurrancers"}
POST /konkurrencer(.:format) {:action=
>"create", :controller=>"konkurrancers"}
new_konkurrencer GET /konkurrencer/new(.:format) {:action=
>"new", :controller=>"konkurrancers"}
edit_konkurrencer GET /konkurrencer/:id/edit(.:format) {:action=
>"edit", :controller=>"konkurrancers"}
konkurrencer GET /konkurrencer/:id(.:format) {:action=
>"show", :controller=>"konkurrancers"}
PUT /konkurrencer/:id(.:format) {:action=
>"update", :controller=>"konkurrancers"}
DELETE /konkurrencer/:id(.:format) {:action=
>"destroy", :controller=>"konkurrancers"}
admin /admin(.:format) {:control
ler=>"admin", :action=>"index"}
statistik /statistik(.:format) {:control
ler=>"public", :action=>"statistik"}
/:id(.:format) {:control
ler=>"kategoris", :action=>"show"}
root /(.:format) {:control
ler=>"public", :action=>"index"}
C:\Rails\konkurranceportalen>
My route file:
Konkurranceportalen::Application.routes.draw do
namespace :admin do
resources :kategoris
resources :konkurrancers
resources :reklamers
end
resources :reklamers
resources :konkurrencer, :controller => 'konkurrancers'
match "/admin" => "admin#index"
match "/statistik" => "public#statistik"
match '/:id' => 'kategoris#show'
root :to => "public#index"
end
try
<%= simple_form_for ['admin', @konkurrancer] do |f| %>
It looks like you're in a name spaced model?
You're using a namespaced model - you must reference the namespace in your form path.
Try this:
<%= simple_form_for [:admin, @konkurrancer] do |f| %>
精彩评论