Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def create
- @where_used = WhereUsed.new(params[:where_used])
- if params[:new_location].to_s.strip.present?
- @new_location = Location.create(:location => params[:new_location])
- @where_used.location_id = @new_location.id
- end
- if params[:location_desc].to_s.strip.present?
- @location_desc = CreativeMedium.create(:location_desc => params[:location_desc])
- @where_used.creative_medium_id = @location_desc.id
- end
- @where_used.creative_medium_id = params[:creative_medium_id] if params[:creative_medium_id].present?
- respond_to do |format|
- if @where_used.save
- format.html { redirect_to(@where_used, :notice => 'Where used was successfully created.') }
- format.xml { render :xml => @where_used, :status => :created, :location => @where_used }
- else
- format.html { render :action => "new" }
- format.xml { render :xml => @where_used.errors, :status => :unprocessable_entity }
- end
- end
- end
- <div id='information'>
- <%= form_for(@where_used) do |f| %>
- <% if @where_used.errors.any? %>
- <div id="error_explanation">
- <h2><%= pluralize(@where_used.errors.count, "error") %> prohibited this where_used from being saved:</h2>
- <ul>
- <% @where_used.errors.full_messages.each do |msg| %>
- <li><%= msg %></li>
- <% end %>
- </ul>
- </div>
- <% end %>
- <div class="field">
- <% if @where_used.creative_medium.present? %>
- <%= @where_used.creative_medium.image_name %>
- <input type="hidden" name="where_used[creative_medium_id]" value="<%=@where_used.creative_medium_id %>" />
- <% else %>
- <%= f.label :creative_medium_id %><br />
- <%= collection_select(:where_used, :creative_medium_id, CreativeMedium.all, :id, :image_name, {:include_blank => false}) %>
- <% end %>
- </div>
- <div class="field">
- <%= f.label :site_used, "Site" %>
- <%= collection_select(:where_used, :site_id, Site.all, :id, :site_used, {:include_blank => false}) %>
- </div>
- <div class="field">
- <%= f.label :location, "Location" %>
- <%= collection_select(:where_used, :location_id, Location.all, :id, :location, {:include_blank => false}) %>
- </div>
- <div class="field">
- <%= f.label :location, "New Location" %>
- <input type="text" name="new_location" />
- </div>
- <div class="field">
- <%= f.label :location_desc, "Description" %><br />
- <input type="text" name="location_desc" />
- </div>
- <div class="actions">
- <%= f.submit 'Update Locations'%>
- </div>
- <% end %>
- </div>
Add Comment
Please, Sign In to add comment