Ruby on Rails Wednesday, August 31, 2011

you were splitting after you saved the model - you want to do that before - or better use a before save call back on the model to split before the model is stored

On Aug 30, 2011 3:28 PM, "Leo M." <lists@ruby-forum.com> wrote:
> Hello!
>
> I'm developing a classical Blog like app, and I'm having some kind of
> issues about posts' tags, because I've correctly installed
> acts_as_taggable and acts_as_taggable_on_steroids gems but none of them
> work, for a controller's mismatch error (due to a Post's tags:string
> attribute I guess), but still, this is not important.
>
> What I want to do is a Blogspot's like schema, so basically there is the
> http://website/search/label/***TAG_NAME*** url, which contains all the
> posts done with this specific tag.
> Well then, I've split the tags and each tag redirect to the correct url,
> which contains all the posts made with the related tag, BUT I just
> manually created the routes and templates.
>
> The problem is : how could I tell to the controller to create an action,
> or a method with the same name of those tags inside the Search
> controller? I was thinking to a Proc, but I have no clue about how to
> structure it. Could you help me?
>
> And also, when I create a new Post, if I write in tags' text_field
> something like "wood,fire", Rails will save the string as a single tag,
> but what I evidently want is to .split(',') this string.
> Yet, I'm not able to find the place in between f.submit and the
> PostsController, where the tags would be sent to the Controller already
> split up.
> Cos, if I put the split after the :
>
> if @post.save
> @post.tags.split(',')
>
> ...in the console I get:
>
>>>Post.last
> => [ #etc etc. tags : "wood,fire"]
>
> and it isn't split. Otherwise, if I put the .split(',') method somewhere
> into the _form I get errors.
>
> So, basically I'm looking for the "place" in the middle between the
> submit action and the Controller's final check. Any idea??? :)
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment