Giter Club home page Giter Club logo

has_permalink's People

Contributors

anoopr avatar bitdeli-chef avatar jjoban2 avatar mkrawc avatar olkarls avatar rshiva avatar tlinke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

has_permalink's Issues

permalink, has title called 'new'

I just notice

if i do have

class Posts < ActiveRecord::Base
has_permalink :title
end

it makes my url looks like "posts/heres-the-title"

but now i do have problem with posts which has title = "new", so the url is "posts/new" and this clash with action "new"

any thoughts how to handle this ?

Cheers

find "String" overrides the AR find. Any reason??

Using this gem, When I do something like this:

User.find "1"
--> It hits find by permalink even if I intend to find by my primary key

Any reason why this is being done? Isnt it better for developers to just write find_by_permalink when they want??

Implicit is EVIL in this case... As it silently hits find_by_permalink. I think, its not required... find should actually find by primary key irregardless of the second argument class type.... In my case, delayed_job gem was converting the argument to string...

Thanks

Jimish

fix_duplication and the % wildcard

Hi,

First of all, thanks for the gem, I love its simplicity.

I just had a weird result today, and looking at the source, it turns out it is a correct behavior, but I find it annoying nonetheless.

I have a Blog model with a title and has_permalink (with the fix_duplication flag set to true) :

# encoding: utf-8
class Blog < ActiveRecord::Base
    attr_accessible :title, :description

    belongs_to :user
    has_many :articles

    has_permalink :title, true

    validates_presence_of :title, :description, :user_id, :permalink
    validates_uniqueness_of :permalink

end

I first created a blog "Ruby on Rails" which resulted in a ruby-on-rails permalink. But then I created a blog "Ruby", which resulted in a ruby-1 permalink. I expected ruby. But looking at the code :

 # Autofix duplication of permalinks
    def fix_duplication(permalink)
      if auto_fix_duplication
        n = self.class.where(["permalink LIKE ?", "#{permalink}%"]).count

        if n > 0
          resolve_duplication(permalink, n)
        else
          permalink
        end
      else
        permalink
      end
    end

The % wildcard is responsible for my ruby-1 permalink. So, is this what is really intended ?

Is it possible to simply use '=' ?

Thank you for your time.

Update permalink for a custom method

Hi,
I used has_permalink in one of my Rails application. I defined a custom method to generate permalink for Model.

For some records it is generating same permalink.

So, how can I update the permalink when the model title or the attributes I defined in my method get updated.

Thanks in advance

Cannot generate migration under Rails 4

Hi. It looks like the migration generator is broken with Rails 4. Here is my stacktrace

$ bin/rails generate has_permalink Products
/usr/lib/ruby/gems/2.2.0/gems/railties-4.1.5/lib/rails/generators/actions/create_migration.rb:13:in `migration_file_name': protected method `migration_file_name' called for #<HasPermalinkGenerator:0x000000049d8ba0> (NoMethodError)
        from /usr/lib/ruby/gems/2.2.0/gems/railties-4.1.5/lib/rails/generators/actions/create_migration.rb:34:in `existing_migration'
        from /usr/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/actions/empty_directory.rb:112:in `invoke_with_conflict_check'
        from /usr/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/actions/create_file.rb:60:in `invoke!'
        from /usr/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/actions.rb:94:in `action'
        from /usr/lib/ruby/gems/2.2.0/gems/railties-4.1.5/lib/rails/generators/migration.rb:34:in `create_migration'
        from /usr/lib/ruby/gems/2.2.0/gems/railties-4.1.5/lib/rails/generators/migration.rb:63:in `migration_template'
        from /home/goudale/.bundler/ruby/2.2.0/has_permalink-732d115169d0/lib/generators/has_permalink_generator.rb:11:in `generate_migration'
        from /usr/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
        from /usr/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
        from /usr/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all'
        from /usr/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each'
        from /usr/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map'
        from /usr/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all'
        from /usr/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch'
        from /usr/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
        from /usr/lib/ruby/gems/2.2.0/gems/railties-4.1.5/lib/rails/generators.rb:157:in `invoke'
        from /usr/lib/ruby/gems/2.2.0/gems/railties-4.1.5/lib/rails/commands/generate.rb:11:in `<top (required)>'
        from /usr/lib/ruby/gems/2.2.0/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `require'
        from /usr/lib/ruby/gems/2.2.0/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `block in require'
        from /usr/lib/ruby/gems/2.2.0/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:232:in `load_dependency'
        from /usr/lib/ruby/gems/2.2.0/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `require'
        from /usr/lib/ruby/gems/2.2.0/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:135:in `generate_or_destroy'
        from /usr/lib/ruby/gems/2.2.0/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:51:in `generate'
        from /usr/lib/ruby/gems/2.2.0/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
        from /usr/lib/ruby/gems/2.2.0/gems/railties-4.1.5/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

Please let me know if you need more informations

Syntax Error: has_permalink / lib / tasks / has_permalink.rake

There is an error in the recuse statement below. Ideally, it shouldn't have elsif in rescue.

Please check.

namespace :has_permalink do
  desc 'Generate permalinks for [MODEL]'
  task :generate_permalinks, [:model_name] => [:environment] do |t, args|
    begin
      model_name = args.first[1]
    rescue
      puts "ERROR: You need to pass the name of the model as an argument."
      puts "Try this: 'rake has_permalink:generate_permalinks[MODEL]'"
    elsif model_name.include?("::")  # Generating permalinks for class inside a module For e.g "ActsAsTaggableOn::Tag"
      get_class_and_generate_permalink(model_name)      
    else
      generate_permalinks(model_name)
    end
  end
end

permalink not unique

Hi,
for some reason i can create duplicate urls in my model.
I have a model called product with attribute :name
so I change the configuration to the following

has_permalink :name

all the crud actions in the corresponding controller make use of Product.find_by_permalink(params[:id])
as described on the intro page.
For some reason, i stil can create duplicate permalinks, and consequently the show method is always pointing to the first entry that has been created..

So I hope its just an "application" error and I look forward to hearing from you.

best philip

p.s. anyhow, i like the gem, since it is very slim

Data not being populated into permalink field ?

I have a model called "Users" with name,email as its field and trying to make the name field as the permalink , I got the permalink field into my model, but it is showing NULL for my existing data ,

Here is my Snippet of "user.rb"
.....
class User < ActiveRecord::Base
has_permalink :name
attr_accessible :name, :email, :password, :password_confirmation
..........

and when I executed the command
rake has_permalink:generate_permalinks[User]
it says " Congratulations! 'User' has permalinks!"
but the permalink field is still showing NULL values for existing fields but it is populating for the new records added

before_validation to generate permalink if nil not working

If my title has content and my permalink field is nil.. it does not generate the permalink.

I try from the console many things and it just does not work

ruby 1.9.2
rails 3.2.3

if I do this to my model it works

 before_validation do |record|
    record.generate_permalink! if record.permalink.blank?
 end

You can create duplicates of perma_link for one model

For example. you have a Blog model where you create the same title on 2 or more.

I create a blog prost with title "Lean development" it creates a perma_link like lean-development, if you create it again it creates a perma_link with the same as the previous one.

It should maybe add an index at the end or something.

Transliteration possible?

show.name
=> "Σαββατογεννημένες"
[9] pry(main)> show.generate_permalink!
   (13.6ms)  SELECT COUNT(*) FROM `shows`  WHERE (permalink = '')
  Show Load (150.6ms)  SELECT `shows`.* FROM `shows`  WHERE (permalink LIKE '%')  ORDER BY id
=> "-1000044"

The permalink generation runs on before_validation which is the first callback in the callback chain.
So is there a way to hook into before the generation is run, or some other way to solve this?

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.