Class: Admin::WordpressAccountsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/admin/wordpress_accounts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject


3
4
5
6
7
8
9
10
11
12
# File 'app/controllers/admin/wordpress_accounts_controller.rb', line 3

def create
  @wordpress_account = WordpressAccount.new_by_user(, current_user)
  if @wordpress_account.save
    flash[:notice] = 'Wordpress Account Connected!'
  else
    flash[:error] = 'Wordpress Account Was Not Connected!'
  end
  
  redirect_to "#{root_url}admin/users/#{current_user.id}"
end

#destroyObject


48
49
50
51
52
53
54
55
56
# File 'app/controllers/admin/wordpress_accounts_controller.rb', line 48

def destroy
  @wordpress = WordpressAccount.find(params[:id])
  @wordpress.destroy

  respond_to do |format|
    format.html {redirect_to("#{root_url}admin/users/#{current_user.id}", :notice => 'Wordpress Account deleted!')}
    format.xml  { head :ok }
  end
end

#send_blog_postObject


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/admin/wordpress_accounts_controller.rb', line 29

def send_blog_post
   = WordpressAccount.find_by_user_id(current_user.id)
  if .blank?
    redirect_to("#{root_url}admin/user/#{current_user.id}", :notice => 'Please Add Wordpress Credentials!')
  else
    .blog_password = SecPass::decrypt(.blog_password)
    link = ShortLink.shorten_link("#{root_url}animals/#{params[:animal_uuid]}")
    message = Hash.new
    message['title'] = "#{params[:animal_name]} is ready for adoption!"
    
    message['content'] = "<p><img src='#{params[:animal_picture]}' /></p>
    <p>#{params[:animal_name]} is ready for adoption at <a href='#{link}'>#{link}</a> via <a href='https://twitter.com/hospitium_app'>@hospitium_app</a>.</p>"
    
    WordpressAccount.post(message, )
    redirect_to("#{root_url}admin/animals/#{params[:animal_id]}-#{params[:animal_uuid]}", :notice => 'Wordpress Post Sent', :only_path => true)
  end
end

#updateObject


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/admin/wordpress_accounts_controller.rb', line 14

def update
  @wordpress = WordpressAccount.find(params[:id])
  if params[:wordpress_account]["blog_password"]
    params[:wordpress_account]["blog_password"] = SecPass::encrypt(params[:wordpress_account]["blog_password"])
  end
  respond_to do |format|
    if  @wordpress.update_attributes()
      format.html {redirect_to("#{root_url}admin/users/#{current_user.id}", :notice => 'Wordpress Account Updated!')}
    else
      format.html { render "new" }
    end
  end
end