Results 1 to 2 of 2
Nov 17, 2007, 21:44 #1
- 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:
@story = Story.new(params[:story])
@story.user = @session['user']
if request.post? and @story.save
@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| %>
<%= f.text_field :title %>
short description:<br />
<%= f.text_field :description %>
<%= text_field_tag 'tags', params[:tags] %>
<%= submit_tag %>
<% end %>
Thanks for any help!
Nov 19, 2007, 11:44 #2
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.