Class: Junebug::Controllers::Edit
- Inherits:
-
R
- Object
- R
- Junebug::Controllers::Edit
- Defined in:
- lib/junebug/controllers.rb
Instance Method Summary collapse
Instance Method Details
#get(page_name, version = nil) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/junebug/controllers.rb', line 23 def get page_name, version = nil redirect("#{Junebug.config['url']}/login") and return if @state.user_id.blank? @page_title = "Edit #{page_name}" @page = Page.find(:first, :conditions=>['title = ?', page_name]) @page = Page.create(:title => page_name, :user_id=>@state.user_id) unless @page @page = @page.versions.find_by_version(version) unless version.nil? or version == @page.version.to_s render :edit end |
#post(page_name) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/junebug/controllers.rb', line 32 def post page_name redirect("#{Junebug.config['url']}/login") and return if @state.user_id.blank? if input.submit == 'delete' Page.find_by_title(page_name).destroy() if @state.user_id == 1 redirect Junebug.startpage elsif input.submit == 'save' attrs = { :body => input.post_body, :title => input.post_title, :user_id =>@state.user_id } attrs[:readonly] = input.post_readonly if @state.user_id == 1 if Page.find_or_create_by_title(page_name).update_attributes( attrs ) # redirect Show, input.post_title redirect "#{Junebug.config['url']}/#{input.post_title}" end else redirect "#{Junebug.config['url']}/#{page_name}" end end |