Skip to content

Instantly share code, notes, and snippets.

@universal
Forked from anonymous/gist:6711528
Last active December 23, 2015 23:39
Show Gist options
  • Save universal/6711549 to your computer and use it in GitHub Desktop.
Save universal/6711549 to your computer and use it in GitHub Desktop.
formatting and mutliple files...
class Member < ActiveRecord::Base
belongs_to :project
belongs_to :users
attr_accessible :project_id, :user_id
end
<%= 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 %>
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
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