Skip to content
Browse files

Need help functional

  • Loading branch information...
1 parent 3f7ea80 commit a405452a16d748f5d12205d7e484f1e70b5397a3 @gomayonqui gomayonqui committed Sep 30, 2012
View
43 app/controllers/needhelp_controller.rb
@@ -0,0 +1,43 @@
+class NeedhelpController < ApplicationController
+ def create
+ create_or_edit(current_user, params)
+ redirect_to user_path(current_user.id)
+ end
+
+ private
+ def create_or_edit(current_user, params)
+ repo = Repo.find_by_github_id(params[:id])
+
+ if repo
+ repo.description = params[:description]
+ repo.forks = params[:forks]
+ repo.watchers = params[:watchers]
+ repo.open_issues = params[:open_issues]
+ repo.pushed_at = params[:pushed_at]
+ if(repo.need_help)
+ repo.need_help = false
+ else
+ repo.need_help = true
+ end
+ repo.save
+ else
+ repo = Repo.new
+ repo.user_id = current_user.id
+ repo.name = params[:name]
+ repo.github_url = params[:github_url]
+ repo.need_help = params[:need_help]
+ repo.created_at = params[:created_at]
+ repo.updated_at = params[:updated_at]
+ repo.github_id = params[:id]
+ repo.full_name = params[:full_name]
+ repo.description = params[:description]
+ repo.language = params[:language]
+ repo.forks = params[:forks]
+ repo.watchers = params[:watchers]
+ repo.open_issues = params[:open_issues]
+ repo.pushed_at = params[:pushed_at]
+ repo.need_help = true
+ repo.save
+ end
+ end
+end
View
1 app/models/repo.rb
@@ -2,4 +2,5 @@ class Repo < ActiveRecord::Base
attr_accessible :github_url, :name, :need_help, :user_id
belongs_to :user
+
end
View
2 app/models/user.rb
@@ -1,5 +1,5 @@
class User < ActiveRecord::Base
- attr_accessible :github_id, :name
+ attr_accessible :github_id, :name, :token
has_many :repos
View
20 app/views/users/show.html.erb
@@ -7,7 +7,6 @@
<%= link_to "Wanna Help", user_wannahelp_index_path(current_user) %>
-<%= link_to "Need Help", needhelp_path(current_user) %>
<h2>Following to :)</h2>
@@ -19,12 +18,21 @@
<ul>
-<% @user_repos.each do |r| %>
- <%= form_for(:repo) do |f| %>
+<% @user_repos.each do |repo| %>
+ <%= form_tag(user_needhelp_index_path(current_user), method: :post) do %>
<li>
- <%= f.check_box r[:name] %>
- <%= f.label r[:name] %>
- <%= f.submit "save", class: "btn" %>
+ <%= label_tag repo[:name] %>
+ <%= hidden_field_tag "name", repo[:name] %>
+ <%= hidden_field_tag "id", repo[:id] %>
+ <%= hidden_field_tag "github_url", repo[:html_url] %>
+ <%= hidden_field_tag "full_name", repo[:full_name] %>
+ <%= hidden_field_tag "description", repo[:description] %>
+ <%= hidden_field_tag "language", repo[:language] %>
+ <%= hidden_field_tag "forks", repo[:forks] %>
+ <%= hidden_field_tag "watchers", repo[:watchers] %>
+ <%= hidden_field_tag "open_issues", repo[:open_issues] %>
+ <%= hidden_field_tag "pushed_at", repo[:pushed_at] %>
+ <%= submit_tag "save", class: "btn" %>
</li>
<% end %>
<% end %>
View
2 config/routes.rb
@@ -4,10 +4,10 @@
root :to => "home#index"
match "/auth/:provider/callback" => "sessions#create"
- match "/user/:id/needhelp", :to => "users#needhelp", :as => "needhelp"
resources :users, only: [:show] do
resources :wannahelp
+ resources :needhelp
end
# Sample of regular route:
View
12 db/migrate/20120930072857_add_column_to_repo.rb
@@ -0,0 +1,12 @@
+class AddColumnToRepo < ActiveRecord::Migration
+ def change
+ add_column :repos, :github_id, :integer
+ add_column :repos, :full_name, :string
+ add_column :repos, :description, :text
+ add_column :repos, :language, :string
+ add_column :repos, :forks, :integer
+ add_column :repos, :watchers, :integer
+ add_column :repos, :open_issues, :integer
+ add_column :repos, :pushed_at, :datetime
+ end
+end
View
14 db/schema.rb
@@ -11,15 +11,23 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120930063355) do
+ActiveRecord::Schema.define(:version => 20120930072857) do
create_table "repos", :force => true do |t|
t.integer "user_id"
t.string "name"
t.string "github_url"
t.boolean "need_help"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.integer "github_id"
+ t.string "full_name"
+ t.text "description"
+ t.string "language"
+ t.integer "forks"
+ t.integer "watchers"
+ t.integer "open_issues"
+ t.datetime "pushed_at"
end
create_table "users", :force => true do |t|

0 comments on commit a405452

Please sign in to comment.
Something went wrong with that request. Please try again.