Permalink
Browse files

Fixed some of the issues regarding view code generation

  • Loading branch information...
ashrafuzzaman committed Jun 8, 2012
1 parent 5dc5748 commit 6c9c5db7c3edb6d0d5f2f19eb0aef2e1aaab3fe8
@@ -15,12 +15,24 @@ def copy_view_files
end
end
def add_has_many
inject_into_class "app/models/#{pr.singular_table_name}.rb", pr.class_name, " has_many :#{plural_table_name}\n"
end
protected
def singular_path
"#{pr.singular_table_name}_#{singular_table_name}_path"
end
def index_path
"#{pr.singular_table_name}_#{singular_table_name}_path(@#{pr.singular_table_name})"
end
def resource_path
"[@#{pr.singular_table_name}, @#{singular_table_name}]"
end
def available_views
%w(index show new edit _form)
end
@@ -29,9 +41,12 @@ def parse_attributes!
parent_ar = self.attributes.to_s.scan(/(\w*):references/)[0]
if parent_ar
parent = parent_ar[0]
say(parent, :green)
@pr ||= Resource.new(parent.downcase)
end
if pr.nil?
say 'You need at least one model:references for this to work', :red
exit 1
end
super
end
@@ -26,7 +26,7 @@ def create
respond_to do |format|
if @<%= singular_table_name %>.save
format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %> }
format.html { redirect_to [@<%= pr.singular_table_name %>, @<%= singular_table_name %>], notice: <%= "'#{human_name} was successfully created.'" %> }
format.json { render json: <%= "@#{singular_table_name}" %>, status: :created }
format.js { flash[:notice] = <%= "'#{human_name} was created.'" %> }
else
@@ -42,7 +42,7 @@ def update
respond_to do |format|
if @<%= singular_table_name %>.update_attributes(params[:<%= singular_table_name %>])
format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> }
format.html { redirect_to [@<%= pr.singular_table_name %>, @<%= singular_table_name %>], notice: <%= "'#{human_name} was successfully updated.'" %> }
format.json { head :no_content }
format.js { flash[:notice] = <%= "'#{human_name} was successfully updated.'" %> }
else
@@ -58,7 +58,7 @@ def destroy
@<%= singular_table_name %>.destroy
respond_to do |format|
format.html { redirect_to <%= index_helper %>_url }
format.html { redirect_to <%= "#{pr.singular_table_name}_#{plural_table_name}" %>_path }
format.json { head :no_content }
end
end
@@ -1,4 +1,4 @@
<%%= form_for [@<%= pr.singular_table_name %>, @<%= singular_table_name %>] do |f| %>
<%%= form_for <%= resource_path %> do |f| %>
<%% if @<%= singular_table_name %>.errors.any? %>
<div id="error_explanation">
<h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
@@ -15,10 +15,12 @@
<legend><%= class_name %></legend>
<ul>
<% attributes.each do |attribute| -%>
<% unless attribute.reference? -%>
<li>
<%%= f.label :<%= attribute.name %> %><br />
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
</li>
<% end -%>
<% end -%>
</ul>
</fieldset>
@@ -1,4 +1,4 @@
<%%= render 'form' %>
<%%= link_to 'Show', @<%= singular_table_name %> %> |
<%%= link_to 'Back', <%= index_helper %>_path %>
<%%= link_to 'Show', <%= resource_path %> %> |
<%%= link_to 'Back', <%= index_path %> %>
@@ -17,7 +17,7 @@
<% attributes.each do |attribute| -%>
<td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
<% end -%>
<td><%%= link_to 'Show', <%= singular_path %>(@<%= pr.singular_table_name %>) %></td>
<td><%%= link_to 'Show', <%= resource_path %> %></td>
<td><%%= link_to 'Edit', edit_<%= singular_path %>(@<%= pr.singular_table_name %>, <%= singular_table_name %>) %></td>
<td><%%= link_to 'Destroy', <%= singular_path %>(@<%= pr.singular_table_name %>) %>, confirm: 'Are you sure?', method: :delete %></td>
<%% end %>
@@ -1,3 +1,3 @@
<%%= render 'form' %>
<%%= link_to 'Back', <%= index_helper %>_path %>
<%%= link_to 'Back', <%= index_path %> %>

0 comments on commit 6c9c5db

Please sign in to comment.