I am using rails 3. I have problem in out put so please tell me my
mistake

routes
-------
entermatch '/view_article/:user_id/:article_id' =>
'articles#view_article', :as => :view_article
resources :users do
resources :articles do
resources :comments
end
end


article controller
------------------

def view_article
@user = User.find(params[:user_id])
@article = Article.find(params[:article_id])
@comment = Comment.new
@comments = Comment.find(:all, :conditions => ['article_id =? ',
params[:article_id]])
end


view_article.html.erb
----------------------


<p>
Article Name:
<b><%= @article.name %></b>
</p>

<p>
Topic:
<b><%= @article.topic %></b>
</p>

<p>
Description:
<b><%= @article.description %></b>
</p>
<div id ="notice"></div>

<%#*<div id="comments_count">%>
<%#= pluralize(@article.comments.size, 'comment') %>
<%#*</div>%>


<div id ="comment"></div>
<%= render :partial => "comments/comment", :collection =>
@article.comments %>



<%= form_for(@comment, :url =>
user_article_comments_path(@user,@article), :remote => true) do |f| %>

<div class ="field">
<%= f.label :comment %><br/>
<%= f.text_area :comment, :cols => "60", :rows => "10" %>
</div>

<div class="action">
<%= f.submit 'Post Comment' %>
</div>

<%end%>

<%#*<div id="comments">%>
<%#= render :partial => "comments/comment" %>
<%#*</div>%>


comment controller
-------------------

def create
@comment = Comment.new(params[:comment])
@comment.user_id = params[:user_id]
@comment.article_id = params[:article_id]
if @comment.save
respond_to do |format|
flash[:notice] = "Comment was Successfully created"
format.html { redirect_to view_article_path(params[:user_id],
params[:article_id] ) }
format.js {
render :update do |page|
end
}
end


create.rjs
----------

page.insert_html :bottom, :comment, :partial => 'comment', :object
=> @comment
page[:comment_comment].reset
page.replace_html :notice, flash[:notice]




_comment.html.erb
-------------------



<%= comment.user.email %>
<%= comment.comment %>
<%= time_ago_in_words(comment.created_at) %> ago

so problem is when I submit the form entry is made in database but
view article page not show any change and whe i refresh the page then
change is seen.

please do the needful.
Thanks.

--
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.

Search Discussions

  • Frederick Cheung at Dec 16, 2011 at 9:48 am

    On Dec 16, 9:39 am, guru wrote:

    def create
    @comment = Comment.new(params[:comment])
    @comment.user_id = params[:user_id]
    @comment.article_id = params[:article_id]
    if @comment.save
    respond_to do |format|
    flash[:notice] = "Comment was Successfully created"
    format.html { redirect_to view_article_path(params[:user_id],
    params[:article_id] ) }
    format.js {
    render :update do |page|
    end
    because you're calling render :update here, your template isn't
    getting rendered (much like if you were to tall render :text => 'OK',
    that would also suppress 'normal' template rendering.

    Fred

    --
    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.
  • Guru at Dec 16, 2011 at 9:58 am

    On Dec 16, 2:47 pm, Frederick Cheung wrote:
    On Dec 16, 9:39 am, guru wrote:

    def create
    @comment = Comment.new(params[:comment])
    @comment.user_id = params[:user_id]
    @comment.article_id = params[:article_id]
    if @comment.save
    respond_to do |format|
    flash[:notice] = "Comment was Successfully created"
    format.html { redirect_to view_article_path(params[:user_id],
    params[:article_id] ) }
    format.js {
    render :update do |page|
    end
    because you're calling render :update here, your template isn't
    getting rendered (much like if you were to tall render :text => 'OK',
    that would also suppress 'normal' template rendering.

    Fred

    thanks for your answer .
    so how do i render the parcial?
    can you explain/
    thanks.

    --
    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.
  • Urjit rajgor at Dec 16, 2011 at 10:33 am
    On 16 December 2011 15:28, guru wrote:
    On Dec 16, 2:47 pm, Frederick Cheung wrote:
    On Dec 16, 9:39 am, guru wrote:

    def create
    @comment = Comment.new(params[:comment])
    @comment.user_id = params[:user_id]
    @comment.article_id = params[:article_id]
    if @comment.save
    respond_to do |format|
    flash[:notice] = "Comment was Successfully created"
    format.html { redirect_to view_article_path(params[:user_id],
    params[:article_id] ) }
    format.js {
    render :update do |page|
    end
    because you're calling render :update here, your template isn't
    getting rendered (much like if you were to tall render :text => 'OK',
    that would also suppress 'normal' template rendering.

    Fred

    thanks for your answer .
    so how do i render the parcial?
    can you explain/
    thanks.

    thanks for your help but I solved it.
    --
    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.

    --
    regards
    Urjit Rajgor

    --
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 16, '11 at 9:45a
activeDec 16, '11 at 10:33a
posts4
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Urjit rajgor: 3 posts Frederick Cheung: 1 post

People

Translate

site design / logo © 2021 Grokbase