Я пытаюсь создать админ бэкэнд для cms.
Итак, у меня есть модель сайта, SitesController и Admin: SitesController.
В /app/views/sites/show.html и /app/views/admin/sites/index.html, new.html и т. Д.
routes.rb
namespace :admin do
resources :sites, :except => :show
end
match '/:slug' => 'sites#show'
EDIT
Выход журнала
Started POST "/admin/sites" for 127.0.0.1 at 2011-07-13 19:03:12 +0200
Processing by Admin::SitesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"8IVTjl6ewasDuBEN6OgczTSdRfxSRPLmPodkrbZEKB8=", "site"=>{"title"=>"Test", "content"=>"abc", "slug"=>"home"}, "commit"=>"Create Site"}
SQL (1.1ms) INSERT INTO "sites" ("content", "created_at", "slug", "title", "updated_at") VALUES (?, ?, ?, ?, ?) [["content", nil], ["created_at", Wed, 13 Jul 2011 17:03:12 UTC +00:00], ["slug", nil], ["title", nil], ["updated_at", Wed, 13 Jul 2011 17:03:12 UTC +00:00]]
Redirected to http://localhost:3000/admin/sites
Completed 302 Found in 12ms
Rails не создает запись с параметрами из формы. Есть идеи?
Вот методы и представление:
админ / сайты # новый
def new
@site = Site.new
respond_to do |format|
format.html # new.html.erb
end
end
админ / сайты # создать
def create
@site = Site.new (params [: site])
respond_to do |format|
if @site.save
format.html { redirect_to admin_sites_path, notice: 'Site was successfully created.' }
else
format.html { render action: "new" }
end
end
админ / сайты / _form
<%= form_for([:admin, @site]) do |f| %>
<% if @site.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@site.errors.count, "error") %> prohibited this admin_site from being saved:</h2>
<ul>
<% @site.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="fields">
<%= f.label :title %><br/>
<%= f.text_field :title %>
</div>
<div class="fields">
<%= f.label :content %><br/>
<%= f.text_area :content %>
</div>
<div class="fields">
<%= f.label :slug %><br/>
<%= f.text_field :slug %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>