Hello,
My problem is when submitting a form with remote_form_for I got a
message that says:"Template is missing
Missing template messages/create.html.erb" so the remote_form_for
searches for a template of the create method instead of just updates
the required div, here is the code:
Here is the link when I call the form:
<%= link_to_remote “Send new SMS”, :url => ‘messages/new_sms’,
:loading => “Element.show(‘loading’)”, :update =>
‘msg_form’,
:complete => “Element.hide(‘loading’)”%>
#new_sms.html.erb:
<% remote_form_for :message, @message, :url => ‘messages/create’,
:loading => “Element.show(‘sending’)”, :update =>
‘messaging_area’,
:complete => “Element.hide(‘loading’)” do |f| %>
#messaging_area is the div that lists sent messages, this div should
be updated by Ajax to show the newly-sent message
|
Message |
<%= f.text_area :text, :id => 'text', :size => '30x10', :class => 'fieldcell' %> |
|
Sender |
<%= f.text_field :sender, :class => 'fieldcell' %> |
|
Number |
<%= f.text_field :number, :class => 'fieldcell' %> |
| <%= f.submit "Send", :class => 'sbutton' %> |
#messages_controller:
.
.
.
def create
@user = User.find(logged_in_user)
@message = Message.new(:text => params[:message][:text],
:sender => params[:message][:sender],
:number => params[:message][:number],
:user_id => logged_in_user.id
)
respond_to do |format|
@numbers_array = params[:message][:number].split(/\,+\s*|\s+/)
# @numbers_from_file = params[:contact][:file].split(/\n/)
if @numbers_array.size <= 16
@message.sendsms
@message.save
@new_count = @user.messages_count + @numbers_array.size
@user.update_attribute(:messages_count,@new_count)
flash[:notice] = ‘Message was successfully created.’
format.html
format.xml { render :xml => @message, :status
=> :created, :location => @message }
elsif
@numbers_array.size > 16
format.html {render :action => "new"}
flash[:notice] = 'More than ur allowed max'
else
format.html { render :action => "new" }
format.xml { render :xml => @message.errors, :status
=> :unprocessable_entity }
end
end
end
.
.
.
I hope everything is clear, I know this is a silly problem but I’ve
read the documentation available about remote_form_for and did a lot
of googling but didn’t know what causes the action to look for a
create.html.erb page !!!
Your help is highly appreciated.
Regards