SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    0 Post(s)
    0 Thread(s)

    How to pass default Param info in a form (add a post to a specific category)


    Regarding the Lenz Book:

    Let's say you have categories and stories.

    You have 3 categories: Music, Movies, and Books.

    Let's say you select the Music category. Now, you would like to post a story link inside the Music category.

    If you want to add a new story to a specific category, what code must you add to your story controller and story view template?

    I have searched and couldn't find much help. It must have something to do with params.

    My story controller contains:

    def new
    @story =[:story])
    @story.user = @session['user']

    if and

    @story.tag_with params[:tags] if params[:tags]

    flash['notice'] = 'your story has been accepted'
    redirect_to :action => 'index'

    (I don't know if I must add filters to the controller to make sure that the specific category id is passed on in the form. )

    My story view is something like:

    <% form_for :story do |f| %>
    title:<br />
    <%= f.text_field :title %>
    short description:<br />
    <%= f.text_field :description %>

    Tags:<br />
    <%= text_field_tag 'tags', params[:tags] %>

    <%= submit_tag %>
    <% end %>

    Thanks for any help!

  2. #2
    SitePoint Addict ruby-lang's Avatar
    Join Date
    Aug 2007
    0 Post(s)
    0 Thread(s)
    Yes, you could do that with params. You would pass the category id in a param in the link to this page, then store it in a hidden_field called category_id. That should do the trick.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts