로드하는 데 문제가 있습니다. 이유가 확실하지 않습니다.레일 3에 제대로로드되지 않는 양식
문제 : 양식 (/ messages/new)을로드하려고하면 빈 페이지가 나타나고 오류 메시지는 표시되지 않습니다.
문제점 : 문제는 메시지와 사용자 간의 연결이 제대로 설정되지 않았기 때문에 양식이 제대로로드되지 않고 수정 방법이 확실하지 않은 것입니다.
배경 : 나는 현재 (아래 첨부) 게시물/INDEX 파일을 통해 양식을 이용하지만 각 사용자에 대해 고유 한 링크 ... 예컨대이 있어야하기 때문에 이것은 잘못된 생각합니다. John이 만든 게시물에 대해 '연락처'버튼을 클릭하면 다른 사용자도 John에게 메시지를 보내야합니다. Simple Private Messaging 플러그인을 사용하고 있습니다.
의견에 감사드립니다.
감사합니다,
파이
메시지> NEW VIEW
<% form_for @message, :url => messages_path(:user_id => @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 %>
메시지의 모델
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
MESSAGES CONTROLLER
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 = "\n\n*Original message*\n\n #{@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
게시물> INDEX보기
<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>
감사에서 공급! 그것은 작동하지만 .. 어떤 사용자 (즉 직접)/메시지/새로운 사용자로부터 독립적 인 액세스하면 몇 가지 이유가 있지만, 페이지가 여전히 열립니다 .. 내가 어떻게 해제합니까? – hikmatyar
http://api.rubyonrails.org에 'ActionController :: Redirecting'을 입력하여 사용자가 페이지에 액세스하지 못하도록하려는 경우 해당 페이지에서 사용자를 리디렉션하기 위해해야 할 일에 대한 문서를 참조하십시오. – lcarpenter