English 中文(简体)
不确定的方法 铁路3项目中的用户信息路径
原标题:Undefined method User message path" in Rails 3 project

我正试图与我的“员额”和“Index”网页链接,让人们向“员额”的创建者发出直接信息(使用简单的私人信息)。

目前,我与新老会有联系,但这不是事事,在我试图进入/新阶段时,我在评估中发现以下错误。

I want to replace the link to /messages/new (in POSTS>INDEX file below) with something better that works. Let me know if you have any thoughts!!

**NoMethodError in Messages#new**

Showing /Users/fkhalid2008/loand/app/views/messages/new.html.erb where line #1 raised:

undefined method `user_messages_path  for #<#<Class:0x12a77f198>:0x12a76dce0>

Extracted source (around line #1):

1: <% form_for @message, :url => user_messages_path(@user) do |f| %>
2:   <p>
3:     To:<br />
4:      <%= f.text_field :to %>

ADDITIONAL INFOATION: 用户自己喜欢Gumtree.com,在那里,用户来到并创建邮局(例如出售汽车),人们回答我寄来的电文(通过简单的普沃特电片)。

感谢!

Faisal

MESSAGES>NEW VIEW

<% form_for @message, :url => user_messages_path(@user) do |f| %>
<p>
To:<br />
    <%= f.text_field :to %>
    <%= error_message_on @message, :to %>
</p>
<p>
Subject:<br />
<%= f.text_field :subject %>
<%= error_message_on @message, :subject %>
</p>
<p>
  Message<br />
  <%= f.text_area :body %>
        <%= error_message_on @message, :body %>
</p>
<p>
  <%= submit_tag "Send" %>
</p>
<% end %>

www.un.org/spanish/ecosoc MESSAGE MODEL

class Message < ActiveRecord::Base

is_private_message

attr_accessor :to

end

<>ROUTES>RB

Mysalary::Application.routes.draw do

resources :messages do
   collection do
     post :delete_selected
     end
   end

resources :users
resources :profiles
resources :pages
resources :posts

get "pages/home"
get "pages/about"
get "pages/legal"
get "pages/feedback"

root :to =>  posts#new 

end

www.un.org/Depts/DGACM/index_french.htm

class MessagesController < ApplicationController

before_filter :set_user

def index
if params[:mailbox] == "sent"
  @messages = @user.sent_messages
else
  @messages = @user.received_messages
end
end

def show
@message = Message.read_message(params[:id], current_user)
end

def new
@message = Message.new

if params[:reply_to]
  @reply_to = @user.received_messages.find(params[:reply_to])
  unless @reply_to.nil?
    @message.to = @reply_to.sender.login
    @message.subject = "Re: #{@reply_to.subject}"
    @message.body = "

*Original message*

 #{@reply_to.body}"
  end
end
end

def create
@message = Message.new(params[:message])
@message.sender = @user
@message.recipient = User.find_by_login(params[:message][:to])

if @message.save
  flash[:notice] = "Message sent"
  redirect_to user_messages_path(@user)
else
  render :action => :new
end
end

def delete_selected
if request.post?
  if params[:delete]
    params[:delete].each { |id|
      @message = Message.find(:first, :conditions => ["messages.id = ? AND (sender_id = ? OR recipient_id = ?)", id, @user, @user])
      @message.mark_deleted(@user) unless @message.nil?
    }
    flash[:notice] = "Messages deleted"
  end
  redirect_to :back
end
end

private
def set_user
 @user = User.first
end
end

<>strong>POSTS>INDEX VIEW

<table class="table table-striped">
<tbody>
<% @posts.each do |post| %>
<tr>
<td>I am a <%= post.title %> getting married in <%= post.job %> in <%= post.location %>, and looking for a <%= post.salary %>. My budget is <%= post.salary %>.</td>
<td> <button class="btn" data-toggle="button" onClick="javascript:location.href =  /messages/new ;" />Contact</button></td>
<td><%= time_ago_in_words(post.created_at) %> ago.</td>
<!--/. 
<td><%= link_to  Show , post %></td>
<td><%= link_to  Edit , edit_post_path(post) %></td>
<td><%= link_to  Destroy , post, :confirm =>  Are you sure? , :method => :delete %></td>
-->
</tr>
<% end %>
</tbody>
</table>
最佳回答

页: 1

如果你想要一条封不动的道路,你需要像你这样的东西。

resources :users do
  resources :messages
end
问题回答

公正使用

<% form_for @message do |f| %>
<% end %>




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签