Giter Club home page Giter Club logo

Comments (9)

stefanoverna avatar stefanoverna commented on July 20, 2024

Hey, activeadmin-globalize3 does not work "natively" with friendly_id. Take a look at the https://github.com/nebirhos/activeadmin-seo gem, which does the job :)

from activeadmin-globalize.

marcusvmsa avatar marcusvmsa commented on July 20, 2024

I'll try this! Thanks

from activeadmin-globalize.

codingluke avatar codingluke commented on July 20, 2024

Hi guys. I came up with the same problem. But couldn't manage it also with the activeadmin-seo gem. So how exactly should my model look, that the slug gets saved for every local? It would also be great to have this case mentioned int the wiki :)

My first configuration:
It works but just creates the slug for the current local

translates :title, :slug 
active_admin_translates :title, :slug
extend FriendlyId
friendly_id :title, :use => [:slugged, :globalize]

My activeadmin-seo test (might be wrong):
With this configuration there is always an error error:

translates :title, :slug 
has_seo_meta :title

active_admin_translates :title, :slug do
  has_seo_meta :title
end

extend FriendlyId
friendly_id :title, :use => [:slugged, :globalize]

The Error:

SQLite3::SQLException: no such column: requisitions.translation_slug: SELECT  "requisitions".* FROM "requisitions"  WHERE "requisitions"."translation_slug" = 'unbelevebal-joby' LIMIT 1

I can not understand why there should be a column "translation_slug"

Thx!

from activeadmin-globalize.

nebirhos avatar nebirhos commented on July 20, 2024

@codingluke you don't need to use the globalize/friendly_id directives as long as you use the gems, so just put:

    active_admin_translates :title do
      validates_presence_of :title
      has_seo_meta :title
    end

in your model to make it work. And yes, we need to write a better documentation!

from activeadmin-globalize.

codingluke avatar codingluke commented on July 20, 2024

Hey @nebirhos. Thanks for your fast answer! I tried this. But Im not sure what your mean with "you don't need to use the globalize/friendly_id directives as long as you use the gems". I also dont really get what has_seo_meta has to do with the friendly_id slug generation.

My code looks now like this:

#translates :title, :slug
#has_seo_meta :title

active_admin_translates :title do
  validates_presence_of :title
  has_seo_meta :title
end

extend FriendlyId
friendly_id :title, :use => :slugged

But now I have this error: Couldn't find Requisition with id=unbelevebal-job
which is for me a sign that, firendly_id gets not triggered corectly.

from activeadmin-globalize.

codingluke avatar codingluke commented on July 20, 2024

Ok I got it! I have to save the title through the method "seo_meta_inputs".
As I can see. the slugs dont gets slugged: "this is my title" should become "this-is-my-title"

1| this is my title ||||||||641|Requisition::Translation|2013-03-26 16:33:19.857561|2013-03-26 16:54:02.317457||

I can see here you configure friendly_id with your slug generator.
https://github.com/nebirhos/activeadmin-seo/blob/master/lib/active_admin/seo/active_record_extension.rb#L12

But here I can see than you use sluggable
https://github.com/nebirhos/activeadmin-seo/blob/master/lib/friendly_id/translated_seo_meta.rb#L41

Am I the only one who has this problem?

Thx

from activeadmin-globalize.

codingluke avatar codingluke commented on July 20, 2024

Hey guys. I was not so happy with the activeadmin-seo, cause I dont use the other functionality. The only thing I want, is that all the slugs gets created. So I analyzed it and found a solution. At the moment a monkey patch.

 FriendlyId::Globalize::Model.class_eval do

  # Override set_slug, so that it works with activeadmin-Globalize
  def set_slug(normalized_slug = nil)
    translations.each do |t|
      I18n.with_locale(t.locale) do
        if should_generate_new_friendly_id?
          normalized_slug = normalize_friendly_id send(friendly_id_config.base)
          generator = friendly_id_config.slug_generator_class.new self, normalized_slug
          send "#{friendly_id_config.slug_column}=", generator.generate
        end
      end
    end
  end
  private :set_slug
end

I will contact also the friendly_id community. What do you think about?

from activeadmin-globalize.

nebirhos avatar nebirhos commented on July 20, 2024

The activeadmin-seo gems among the other things takes care of generating the slug for every translation. When I say you don't need any other directive I mean to get rid of everything except:

class Product < ActiveRecord::Base
  attr_accessible :price
  active_admin_translates :name, :description do
    validates_presence_of :name
    has_seo_meta :name
  end
end

With activeadmin-seo + activeadmin-globalize the slug and other meta tags are attached to the Product::Translation model, so you can get them with

p = Product.first
p.translation.seo_meta.slug

For simplicity you can add a delegation to retrieve the seo_meta association.

I hope this clarifies any doubt!

from activeadmin-globalize.

codingluke avatar codingluke commented on July 20, 2024

@nebirhos I got this. Nothing against the gem, its good for adding meta information and along with this slug generation to models. I just feel better to have a simple solution for my particular need. For example with my solution I still have the ability to define a method for declaring which field gets concatenated for the slug generation. Also, I don't have an additional table and I don't need the special has_seo_meta fields in the formular.
In my project slug generation has just nothing todo with seo_meta fields. Its a thing on his own. I like independent moduls wich solve one problem. Coupling things seams easy In the first view, but can get rally tricky as soon the need gets more complex.

from activeadmin-globalize.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.