Created
May 25, 2013 13:19
-
-
Save thomasstr/5649015 to your computer and use it in GitHub Desktop.
Doesnt get any response from create method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%= simple_form_for(@del_project, url: :del_project ) do |f| %> | |
| <%#= f.error_notification %> | |
| <div class="form-inputs"> | |
| <%= f.input :delete_project, collection: Project.list_domains.split("\n"), prompt: "Velg utviklingssted" %> | |
| <%#= f.input %> | |
| <%= f.button :submit, "Slett", class: "btn btn-danger" %> | |
| </div> | |
| <% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%= simple_form_for(@project, url: {action: :create} ) do |f| %> | |
| <%#= f.error_notification %> | |
| <div class="form-inputs"> | |
| <%= f.input :project_name, placeholder: "Navn på utviklingssted" %> | |
| <%= f.input :project_pass, placeholder: "Database-navn for utviklingssted" %> | |
| <%#= f.input %> | |
| <%= f.button :submit, "Lag", class: "btn btn-success" %> | |
| </div> | |
| <% end %> | |
| <pre><%= @output %></pre> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Project | |
| include ActiveModel::Validations | |
| include ActiveModel::Conversion | |
| extend ActiveModel::Naming | |
| attr_accessor :project_name, :project_pass | |
| attr_accessor :delete_project | |
| validates_presence_of :project_name | |
| validates_presence_of :project_pass | |
| validates_presence_of :delete_project | |
| def initialize(attributes = {}) | |
| attributes.each do |name, value| | |
| send("#{name}=", value) | |
| end | |
| end | |
| def persisted? | |
| false | |
| end | |
| def self.myname(name, pass) | |
| hostname = "192.168.0.16" | |
| username = "xxxxx" | |
| password = "xxxxx" | |
| ssh_port = 22 | |
| begin | |
| Net::SSH.start( hostname, username, :password => password, :port => ssh_port ) do |ssh| | |
| result = ssh.exec!("./myname.sh #{name} #{pass}") | |
| return result | |
| ssh.close | |
| end | |
| rescue | |
| flash[:error] = "Kunne ikke koble til SSH-server..." | |
| end | |
| end | |
| def self.list_domains | |
| hostname = "192.168.0.16" | |
| username = "xxxxx" | |
| password = "xxxxx" | |
| ssh_port = 22 | |
| begin | |
| Net::SSH.start( hostname, username, :password => password, :port => ssh_port ) do|ssh| | |
| result = ssh.exec!("ls /var/www/sites/") | |
| # render inline: result | |
| # result.gsub("\n", "\n") | |
| # result.split(".no") | |
| return result | |
| ssh.close | |
| end | |
| rescue | |
| render inline: "Kunne ikke koble til #{hostname}" | |
| end | |
| end | |
| # def self.delete_project(name) | |
| # end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ProjectController < ApplicationController | |
| # respond_to :html, :json | |
| def new | |
| @project = Project.new | |
| end | |
| def create | |
| @project = Project.new(params[:project]) | |
| if @project.valid? | |
| @output = Project.myname(@project.project_name, @project.project_pass) | |
| flash[:notice] = "Nettsted er laget!" | |
| render "new" | |
| # render text: @output, location: projects_path(@output) | |
| # redirect_to projects_path | |
| else | |
| render "new" | |
| end | |
| end | |
| def list_domains | |
| @domains = Project.list_domains | |
| render "list_domains" | |
| end | |
| def delete_project | |
| @del_project = Project.new | |
| end | |
| def confirm_delete | |
| @del_project = Project.new(params[:del_project]) | |
| if @del_project.valid? | |
| # @confirm = @del_project.delete_project | |
| flash[:notice] = "Nettsted slettet!" | |
| render "delete_project" | |
| else | |
| render "delete_project" | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| match "/projects" => "project#new", as: "projects", via: :get | |
| match "/projects" => "project#create", as: "projects", via: :post | |
| match "/domains" => "project#list_domains" | |
| match "/del_project" => "project#delete_project", via: :get | |
| match "/del_project" => "project#confirm_delete", via: :post, as: :del_project |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment