Topic: Create a wiki using rails

Hello,

Basically i want start with creating a user and page model. I got the user model with devise and the page model using scaffold. Now i am wondering how do i relate them, so that when the user logs in and makes an edit. I am able to tag or show the edit in a way like "Page edited by - UserName/Email"

thanks. You dont have to go in real detail. being brief is fine too smile

Re: Create a wiki using rails

class User << ActiveRecord::Base
  has_many :pages
end

class Page << ActiveRecord::Base
  belongs_to :user
end

make sure your Page model has the attribute :email_of_creator (or whatever you choose)

app/controllers/page_controller.rb:

def new
  @page = Page.new
  @page.email_of_creator = current_user.email
end
def create
  @page = Page.new(params[:page])
end

app/views/page/new.html.erb:

<%= form_for @page do |f| %>
  <%= f.hidden_field :email_of_creator %>
  <%= other fields the user must enter ... %>
<% end %>

app/controllers/page_controller.rb:

def index
  @pages = Page.all()
end

app/views/pages/index.html.erb:

<% @pages.each do |p| %>
  <%= "created by #{p.email_of_creator}" %>
<% end %>
Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: Create a wiki using rails

hi,

thanks so much. I achieved this and much more than this. thanks again. i am wondering how i implement the history feature. As in, it shows diff and compare version. In short, how do i implement a versioning feature in the wiki. Where all the edits are version. is papertrail a nice tool ? can i get a start for that ?

thanks