Created
September 26, 2013 08:44
-
-
Save anonymous/6711528 to your computer and use it in GitHub Desktop.
This file contains 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
new.html.erb | |
<%= simple_form_for(@project) do |f| %> | |
<%= f.input :projectname %> | |
<%= f.label "Select Client" %> | |
<%= f.collection_select(:user_id, User.find(:all, :conditions => ["flag = 3"]), :id, :name, :class =>"user") %> | |
<%= f.hidden_field :created_by, :value => current_user.name %> | |
<%= label_tag(:description, "Description :") %> | |
<%= f.text_area(:description, :cols => 5, :rows => 5) %> | |
<%= f.input :start_date, :label => "Start date", :required => true %> | |
<%= f.input :end_date, :label => "End date", :required => true %> | |
<h5>Members</h5> | |
<% @use.each do |u| %> | |
<%= f.simple_fields_for :members do |s| %> | |
<%= s.check_box :user_id, {}, u.id %><%= u.name %> | |
<% end %> | |
<% end %><br><br> | |
<%= f.submit "save", :class => 'btn btn-huge btn-info btn-embossed mlm' %> | |
<% end %> | |
project.rb | |
class Project < ActiveRecord::Base | |
has_many :members | |
belongs_to :user | |
attr_accessible :projectname, :user_id, :clientname, :created_by, :description, :start_date, :end_date, :members_attributes | |
accepts_nested_attributes_for :members, :allow_destroy => true | |
end | |
member.rb | |
class Member < ActiveRecord::Base | |
belongs_to :project | |
belongs_to :users | |
attr_accessible :project_id, :user_id | |
end | |
controller | |
class ProjectsController < ApplicationController | |
def index | |
@projects = Project.all | |
end | |
def show | |
@project = Project.find(params[:id]) | |
end | |
def new | |
@use = User.where('flag = 1 or flag = 2') | |
@project = Project.new | |
@project.members.build | |
end | |
def create | |
@project = Project.new(params[:project]) | |
if @project.save | |
redirect_to @project, notice: 'Project Created Successfully.' | |
else | |
render :action => 'new' | |
end | |
end | |
def edit | |
@use = User.where('flag = 1 or flag = 2') | |
@project = Project.find(params[:id]) | |
end | |
def update | |
@project = Project.find(params[:id]) | |
if @project.update_attributes(params[:project]) | |
redirect_to @project, notice: 'Project Updated Successfully.' | |
else | |
render :action => 'edit' | |
end | |
end | |
def destroy | |
@project = Project.find(params[:id]) | |
@project.destroy | |
redirect_to projects_url, notice: 'Project Destroyed Successfully.' | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment