Rails ignores rendering and redirect_to

I have a very simple question with rails, but I can not find the answer anywhere. I assume some of the problems are related to me after the Rails 1.2 tutorial with Rails 2.1. Anyway..

I am writing a blog system and I am implementing a bit of comments. I have comments displaying a penalty as soon as I created them using the script / console, but getting the comment form itself is a hard bit.

In posts_controller.rb I have

  def comment
    Post.find(params[:id]).comments.create(params[:comment])
    flash[:notice] = "Added comment"
    #render :action => show
    redirect_to :action => show
  end  

and in show.html.erb (view) I have

<%= form_tag :action => "comment", :id => @post %>
  <%= text_area "comment", "body" %><br>
  <%= submit_tag "Post Comment" %>

When I submit the form, it tries to go to UBL / posts / comment / 1, which is clearly wrong, and complains that it cannot find the template. Obviously, I don’t want the template to be there, because I told him to redirect the show to the action, because I want it to simply display the page after showing with a new comment.

(render: action = > show), redirect_to, .

, - , ?

+5
3

redirect_to :action => 'show', :id => params[:id] ?

+8

Rails 2.1 " RESTful". show REST, rails.

Rails , : show . , . , "1". , URL-,

Rails 2.1 :

  • index -
  • create -
  • show - ( ). , , , "" .

new ( , ) edit ( , ) update ( ) destroy (duh), , .

? Rails 2.1.

0

Yes, you are using the old rail style.

Something new:

   form_for :comment, :url => { :post_id => @post } do |f|
     f.text_area :body
     submit_tag "Post"
   end

you can use resources for posts and comments, search google for a better tutorial or set rails 1.2.6:

gem install -v 1.2.6 rails
-1
source

All Articles