Skip to content

Instantly share code, notes, and snippets.

@amacgregor
Created May 19, 2011 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amacgregor/981927 to your computer and use it in GitHub Desktop.
Save amacgregor/981927 to your computer and use it in GitHub Desktop.
snippets.rb
.group
=f.label :title
=f.error_message_on :title
=f.text_field :title, :class => :text_field
%span.description Ex: a simple text
.group
=f.label :code
=f.error_message_on :code
~f.text_area :code, :class => :text_area
%span.description Ex: a simple text
.group
=f.label :account_id
=f.error_message_on :account_id
=f.select :account_id, :options => @accounts.map { |a| [a.id, a.name] }, :class => :select_field
%span.description Ex: a simple text
.group.navform.wat-cf
=f.submit pat(:save), :class => :button
=f.submit pat(:cancel), :onclick => "window.location='#{url(:snippets, :index)}';return false", :class => :button
Admin.controllers :snippets do
get :index do
@snippets = Snippet.all
render 'snippets/index'
end
get :new do
@snippet = Snippet.new
render 'snippets/new'
end
post :create do
@snippet = Snippet.new(params[:snippet])
@accounts = Account.all
if @snippet.save
flash[:notice] = 'Snippet was successfully created.'
redirect url(:snippets, :edit, :id => @snippet.id)
else
render 'snippets/new'
end
end
get :edit, :with => :id do
@snippet = Snippet.find(params[:id])
render 'snippets/edit'
end
put :update, :with => :id do
@snippet = Snippet.find(params[:id])
if @snippet.update_attributes(params[:snippet])
flash[:notice] = 'Snippet was successfully updated.'
redirect url(:snippets, :edit, :id => @snippet.id)
else
render 'snippets/edit'
end
end
delete :destroy, :with => :id do
snippet = Snippet.find(params[:id])
if snippet.destroy
flash[:notice] = 'Snippet was successfully destroyed.'
else
flash[:error] = 'Impossible destroy Snippet!'
end
redirect url(:snippets, :index)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment