Ruby on Rails Monday, September 29, 2014

On 29 September 2014 08:11, Aspiring.Student.programmer
<sabrina.ncx@gmail.com> wrote:
> Hey
>
> In section 5.13 of getting started with rails it shows how to delete data
> from the database. When i added the code i got this error. I have checked my
> code and cant find any problems. Help Please
>
> <img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAABVYAAA...

You say it is an error but it does not look like an error message, it
looks like some html generated by an image_tag or similar. Show us
the line in your view that is generating that. If it is not coming
from a line in your view what do you see in development.log when it
happens?

Colin



>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/7c102d01-c473-4d0d-b8fb-152df9d7cbed%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvq%2BsGewfaMpsyF%2BiPpAWA_PYZ9g1-4XKTr1dJfFUMaDQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

I finally got it working in ActiveAdmin without a custom form. I'll post how I did it for references if somebody need.
First I set my custom attributes in the LineItem model:

class LineItem < ActiveRecord::Base
attr_accessor :source
attr_accessor :target

(it doesn't work adding :source and :target to the ActiveAdmin file under permit_params, I get an error that there are no column with :source/:target if not added to the model with attr_accessor)

ActiveAdmin.register Order do

  permit_params :id, :title,
                line_items_attributes: [:id, :order_id, :language_pair_id, :source, :target]

  form do |f|
    f.inputs do
      f.input :title
      f.has_many :line_items, :allow_destroy => true do |cf|
        cf.input :source, :collection => Language.pluck(:lang)
        cf.input :target, :collection => Language.pluck(:lang)
      end
    end
    f.actions
  end

  controller do
    def create
      @order = Order.create(:title => params[:order][:title])
      params[:order][:line_items_attributes].each do |x, y|
        source = Language.find_by_lang(y[:source])
        target = Language.find_by_lang(y[:target])
        pair = LanguagePair.find_by(:source_id => source.id, :target_id => target.id)
        @order.line_items.create(:language_pair => pair)
      end
      create!
    end
  end
end

it work flawlessly.

Thank you all for the help.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8ee16610-4b5b-42a6-9327-7098a42e69df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Hey

In section 5.13 of getting started with rails it shows how to delete data from the database. When i added the code i got this error. I have checked my code and cant find any problems. Help Please


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7c102d01-c473-4d0d-b8fb-152df9d7cbed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.