class PostsController < ApplicationController
  # GET /posts
  # GET /posts.xml
  def index
    @posts = Post.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @posts }
    end
  end

  # GET /posts/1
  # GET /posts/1.xml
  def show
    @post = Post.find_by_title(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @post }
    end
  end

  # GET /posts/new
  # GET /posts/new.xml
  def new
    @post = Post.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @post }
    end
  end

  # GET /posts/1/edit
  def edit
    @post = Post.find(params[:id])
  end

  # POST /posts
  # POST /posts.xml
  def create
    @post = Post.new(params[:post])

    respond_to do |format|
      if @post.save
        flash[:notice] = 'Post was successfully created.'
        format.html { redirect_to(@post) }
        format.xml  { render :xml => @post, :status
=> :created, :location => @post }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @post.errors, :status
=> :unprocessable_entity }
      end
    end
  end

  # PUT /posts/1
  # PUT /posts/1.xml
  def update
    @post = Post.find(params[:id])

    respond_to do |format|
      if @post.update_attributes(params[:post])
        flash[:notice] = 'Post was successfully updated.'
        format.html { redirect_to(@post) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @post.errors, :status
=> :unprocessable_entity }
      end
    end
  end

  # DELETE /posts/1
  # DELETE /posts/1.xml
  def destroy
    @post = Post.find(params[:id])
    @post.destroy

    respond_to do |format|
      format.html { redirect_to(posts_url) }
      format.xml  { head :ok }
    end
  end
end


On Sep 23, 9:21 am, luis tomas <[EMAIL PROTECTED]> wrote:
> That is the RHTML. The actions take effect in the controller. Post it.
>
> On Sep 18, 7:29 pm, Presario 6331RSH HAM <[EMAIL PROTECTED]> wrote:
>
> > Ok!
>
> > <h1>Showing post</h1>
>
> > <table border="1">
> >   <tr>
> >     <th width="10%"><em><b>Title:</b></em></th>
> >     <td width="90%"><b><%=h @post.title %></b></td>
> >   </tr>
> >   <tr>
> >      <th width="10%"><em>Message:</em></th>
> >      <td width="90%"><%=h @post.body %></td>
> >   </tr>
>
> > </table>
>
> > <%= link_to 'Edit', edit_post_path(@post) %> |
> > <%= link_to 'Delete',{:action => 'destroy', :id =>
> > @post.title}, :confirm => 'Are you sure?', :post => true %> |
>
> > <%= link_to 'Back', posts_path %>
>
> > This is what isn't working. I would like to get it to work. I want the
> > page to go away, delete the data and take me back to index.html
>
> > On Sep 16, 6:09 am, luis tomas <[EMAIL PROTECTED]> wrote:
>
> > > Destroy method works with any database because is an ActiveRecord's
> > > method.
> > > Post your code.
>
> > > On Sep 15, 10:43 pm, Presario 6331RSH HAM <[EMAIL PROTECTED]> wrote:
>
> > > > Hey all,
>
> > > >    I built the Blog from examples and samples and my blog recipe.txt.
> > > > Now I have modified it to
> > > > make it prettier and one of the things that I did was put the Delete
> > > > link in the post.show.html.
> > > > It doesn't work though and I need help using Delete ('destroy') so I
> > > > can delete them from the database. Do these work the same for sqlite3
> > > > as they do for mysql? Perhaps one may not delete the page that they
> > > > are on also but at least take it out of the db before navigating away
> > > > from the page we're on?
>
> > > > Cookin' with Rails?- Hide quoted text -
>
> > > - Show quoted text -

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "ruby-on-rails-programming-with-passion" group.
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/ruby-on-rails-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to