1

I'm using Rails3, devise, and acts_as_taggable_on.
In user's edit page I added tag input box for each user.
But user might input something like this

Word1, Word2. Word3

They should be separated by ',(comma)'

So I want to check and replace particular characters to exclude.
For that, I added this to my User model

before_update :check_taglist

def check_taglist
        tag_list = params[:tag_list].gsub(/[ ]+/," ")
        tag_list = params[:tag_list].gsub(/[.]+/,",")
end

But what it says error now:(

undefined local variable or method `params' for

How can I fix this???

HUSTEN
  • 5,117
  • 4
  • 24
  • 38
  • I agree with Leo Correa, you'll either have to keep this in your controller or pass to your model from your controller. – simonmorley Dec 13 '12 at 19:11

1 Answers1

1

The problem is that you are trying to access the params hash from your model and your model has no knowledge of what params is. Either place that looks like logic that should be in the controller?

Also, this might help you out too.

This is another way to update a user without going through devise

Rails: Devise: How can I edit user information?

Community
  • 1
  • 1
Leo Correa
  • 19,131
  • 2
  • 53
  • 71
  • yeah. That's what I wanted to do first. But what the problem is using devise. Updating user model is relying on devise plugin. So update method is written in somewhere out of rails app. So I added def before_update to my registration controller that I already had. But it seemed that its transaction didn't help to replace:( – HUSTEN Dec 13 '12 at 19:22
  • Have you tried exposing the devise controllers? I know they have an option to do that. – Leo Correa Dec 13 '12 at 19:50
  • no I haven't do you mean I can extract all of the files for devise to my app?? – HUSTEN Dec 13 '12 at 19:51
  • https://github.com/plataformatec/devise it shows you there how to customize your controllers. Reading through the documentation you might find a better way to do what you want to do. – Leo Correa Dec 13 '12 at 19:54