Search Results

Search found 5 results on 1 pages for 'dustmoo'.

Page 1/1 | 1 

  • Ajax, Multiple Attachments and Paperclip question.

    - by dustmoo
    Alright everyone this is a bit of a complicated setup so if I need to clarify the question just let me know. I have a model: class IconSet < ActiveRecord::Base has_many :icon_graphics end This Model has many icongraphics: class IconGraphic < ActiveRecord::Base belongs_to :icon_set has_attached_file :icon has_attached_file :flagged end As you can see, IconGraphic has two attached files, basically two different versions of the icon that I want to load. Now, this setup is working okay if I edit the icongraphic's individually, however, for ease of use, I have all the icon graphics editable under the IconSet. When you edit the icon set the form loads a partial for the icongraphics: <% form_for @icon_set, :html => {:class => 'nice', :multipart => true} do |f| %> <fieldset> <%= f.error_messages %> <p> <%= f.label :name %> <%= f.text_field :name, :class => "text_input" %> </p> <!-- Loaded Partial for icongraphics --> <div id="icon_graphics"> <%= render :partial => 'icon_graphic', :collection => @icon_set.icon_graphics %> </div> <div class="add_link"> <%= link_to_function "Add an Icon" do |page| page.insert_html :bottom, :icon_graphics, :partial => 'icon_graphic', :object => IconGraphic.new end %> </div> <p><%= f.submit "Submit" %></p> </fieldset> <% end %> This is based largely off of Ryan's Complex Forms Railscast. The partial loads the file_field forms: <div class="icon_graphic"> <% fields_for "icon_set[icon_graphic_attributes][]", icon_graphic do |icon_form|-%> <%- if icon_graphic.new_record? -%> <strong>Upload Icon: </strong><%= icon_form.file_field :icon, :index => nil %><br/> <strong>Upload Flagged Icon: </strong><%= icon_form.file_field :flagged, :index => nil %> <%= link_to_function image_tag('remove_16.png'), "this.up('.icon_graphic').remove()"%><br/> <% else -%> <%= image_tag icon_graphic.icon.url %><br/> <strong>Replace <%= icon_graphic.icon_file_name %>: </strong><%= icon_form.file_field :icon, :index => nil %><br /> <% if icon_graphic.flagged_file_name.blank? -%> <strong>Upload Flagged Icon: </strong><%= icon_form.file_field :flagged, :index => nil %> <% else -%> <strong>Replace <%= icon_graphic.flagged_file_name %>: </strong><%= icon_form.file_field :flagged, :index => nil %> <%= icon_form.hidden_field :flagged, :index => nil %> <% end -%> <%= link_to_function image_tag('remove_16.png'), "mark_for_destroy(this, '.icon_graphic')"%><br/> <%= icon_form.hidden_field :id, :index => nil %> <%= icon_form.hidden_field :icon, :index => nil %> <%= icon_form.hidden_field :should_destroy, :index => nil, :class => 'should_destroy' %> <br/><br/> <%- end -%> <% end -%> </div> Now, this is looking fine when I add new icons, and fill both fields. However, if I edit the IconSet after the fact, and perhaps try to replace the icon with a new one, or if I uploaded only one of the set and try to add the second attachment, paperclip doesn't put the attachments with the right IconGraphic Model. It seems that even though I have the IconGraphic ID in each partial, <%= icon_form.hidden_field :id, :index => nil %> it seems that paperclip either creates a new IconGraphic or attaches it to the wrong one. This all happens when you save the IconSet, which is setup to save the IconGraphic attributes. I know this is complicated.. I may just have to go to editing each icon individually, but if anyone can help, I would appreciate it.

    Read the article

  • How to sort a Ruby Hash by number value?

    - by dustmoo
    Hi everyone, I have a counter hash that I am trying to sort by count. The problem I am running into is that the default Hash.sort function sorts numbers like strings rather than by number size. i.e. Given Hash: metrics = {"sitea.com" => 745, "siteb.com" => 9, "sitec.com" => 10 } Running this code: metrics.sort {|a1,a2| a2[1]<=>a1[1]} will return a sorted array: [ 'siteb.com', 9, 'sitea.com', 745, 'sitec.com', 10] Even though 745 is a larger number than 9, 9 will appear first in the list. When trying to show who has the top count, this is making my life difficult. :) Any ideas on how to sort a hash (or an array even) by number value size? I appreciate any help.

    Read the article

  • Rails each loop insert tag every 6 items?

    - by dustmoo
    Hello Stack Anon, I have X number of image objects that I need to loop through in a view and want to create a new div every 6 objects or so (for a gallery). I have looked at cycle but it seems to change every other record. Does anyone know of a way to insert code into a view every 6 times? I could probably do it with nested loops but I am kinda stumped on this one. Thanks!

    Read the article

  • Forms blank when rendering a partial when using a collection of objects. Help!

    - by dustmoo
    Alright, I know my title is a little obscure but it best describes the problem I am having. Essentially, I have a list of users, and want to be able to edit their information in-line using AJAX. Since the users are showing up in rows, I am using a partial to render the data and the forms (which will be hidden initially by the ajax), however, when the rows are rendered currently only the last item has it's form's fields populated. I suspect this has something to do with the fact that all the form fields have the same id's and it is confusing the DOM. But I don't know how to make sure the id's are unique. Here is a small example: In my view: <%= render :partial => 'shared/user', :collection => @users %> My partial (broke down to just the form) note that I am using the local variable "user" <% form_for user, :html => {:multipart => true} do |f| -%> <%= f.label :name, "Name*" %> <%= f.text_field :title, :class => "input" %> <%= f.label :Address, "Address" %> <%= f.text_field :address, :class => "input" %> <%= f.label :description, "Description*" %> <%= f.text_area :description, :class => "input" %> <% end -%> When the html is rendered each form has a unique id (for the id of the user) but the elements themselves all have the same id, and only the last user form is actually getting populated with values. Does anyone have any ideas?? :) Thanks in advance!

    Read the article

  • Model association changes in production environment, specifically converting a model to polymorphic?

    - by dustmoo
    Hi everyone, I was hoping I could get feedback on major changes to how a model works in an app that is in production already. In my case I have a model Record, that has_many PhoneNumbers. Currently it is a typical has_many belongs_to association with a record having many PhoneNumbers. Of course, I now have a feature of adding temporary, user generated records and these records will have PhoneNumbers too. I 'could' just add the user_record_id to the PhoneNumber model, but wouldn't it be better for this to be a polymorphic association? And if so, if you change how a model associates, how in the heck would I update the production database without breaking everything? .< Anyway, just looking for best practices in a situation like this. Thanks!

    Read the article

1