Last active
December 27, 2015 18:09
-
-
Save victorcreed/7367094 to your computer and use it in GitHub Desktop.
really lazy and dont want to create mess in VIEW, so i used splat to passing dynamic parameters
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
<%= simple_form_for @job, html: { class: "form-horizontal" } do |f| %> | |
<% new_and_edit_form_fields.each do |column| %> | |
<%= f.input *column %> | |
<% end %> | |
<% end %> |
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
class Job < ActiveRecord::Base | |
belongs_to :user | |
def self.public_attributes | |
column_names.map(&:to_sym).reject{ |x| [:id, :updated_at, :created_at, :user_id].include?(x) } | |
end | |
attr_accessible *public_attributes | |
end |
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
module JobsHelper | |
def new_and_edit_form_fields | |
Job.public_attributes.keep_if{ |x| ![:user_id, :status, :published].include?(x) }.map do |jp| | |
send("#{jp.to_s}_helper") rescue jp | |
end | |
end | |
def subject_helper | |
[:subject, {wrapper_html: { class: "form-holder" }, input_html: { cols: 5, rows: 3} }] | |
end | |
def grade_helper | |
[:grade, { collection: ["elemantry"], wrapper_html: { class: "form-holder" }}] | |
end | |
def covered_teacher_contact_information_helper | |
[:covered_teacher_contact_information, { wraper_html: { class: "form-holder" }}] | |
end | |
end |
Good Work..
Nice innovation would give it a try..
Thanks for sharing Experience..
pretty handy, good job.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ye thanks @muaazrafi its seems enhanced version, ill try.