Created
May 19, 2011 14:13
-
-
Save jlebrech/980828 to your computer and use it in GitHub Desktop.
Intra user messaging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= simple_form_for(@memo) do |f| | |
- if @memo.errors.any? | |
#error_explanation | |
%h2 | |
= pluralize(@memo.errors.count, "error") | |
prohibited this memo from being saved: | |
%ul | |
- @memo.errors.full_messages.each do |msg| | |
%li= msg | |
.inputs | |
= f.input :content | |
.actions | |
= f.button :submit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%h1 Listing memos | |
- @memos.each do |memo| | |
%ul | |
%ul | |
%li= memo.sender.login | |
%li= memo.content | |
- if memo == @memos.last | |
= render 'form' | |
%br | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MemosController < ApplicationController | |
# GET /memos | |
# GET /memos.xml | |
def index | |
# change the index to only show chronological messages between the current user and the other user | |
@memos = Memo.where( | |
"(sender_id = ? or receiver_id = ?) and (sender_id = ? or receiver_id = ?)", | |
current_user, current_user, | |
params[:other_user], | |
params[:other_user] | |
) | |
@memo = Memo.new | |
@other_user = User.find(params[:other_user]) | |
respond_to do |format| | |
format.html # index.html.erb | |
format.xml { render :xml => @memos } | |
end | |
end | |
# POST /memos | |
# POST /memos.xml | |
def create | |
@memo = Memo.new(params[:memo]) | |
@memo.sender = current_user | |
respond_to do |format| | |
if @memo.save | |
format.html { redirect_to( :action => "index", :other_user => params[:other_user]) } | |
format.xml { render :xml => @memo, :status => :created, :location => @memo } | |
else | |
format.html { redirect_to( :action => "index", :other_user => params[:other_user]) } | |
format.xml { render :xml => @memo.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I feel its because you are not passing the params[:other_users] from your form to create method.
I am not sure about haml syntax but if you want to pass params[:other_user] from your form to create method, you can use form_tag.
I have used it many times.
Alternatively, you can create a temp table and store value of params[:other_user] in that table when you are in action 'new' and retrieve it when you are in action 'create'.
Hope this helps!
cheers.