I am building message app in rails where user can send message from templates. I have a database of templates, and the user can select templates as per category.
In my message model, I want to render the template dynamically based on category selected. I looked for examples on google, but was not able to find a relevant solution.
This is my message form:
<%= form_for #message, :html => {:multipart => true} do |m| %>
<%= m.select :biz_case, options_for_select(Message::Bcase), :prompt => "Select business case" %>
<%= m.text_field :subject, :class => "message-text", :placeholder => "Subject" %>
<div class="message-body">
<%= m.text_area :message, :class => "message-body", :class => "redactor", :placeholder => "Your content" %>
</div>
<%= m.select :user_type, options_for_select(Customer::CType), :prompt => "Customer segment" %>
<%= m.submit %>
<% end %>
In the above form, I am looking to display the subject and body based on the selected business case. Something like:
if biz_case == "promote"
subject = #template.subject where ("biz_case = ?", "promote")
message = #template.content where ("biz_case = ?", "promote")
end
The subject and message would be displayed in input text fields.
Can anyone tell me how to do this?
in your method:
#subject = #template.subject where ("biz_case = ?", "promote")
in view:
<%= m.text_field :subject, :value => #subject, :class => "message-text", :placeholder => "Subject" %>
Related
I'm just trying to send email from within my application. For some reason, the email isn't being sent. Am I missing a step? Here is the contact_us documentation. I followed it exactly. https://github.com/jdutil/contact_us. How can I get it to mail?
Here is my view:
<div class="container">
<h2><%= t('.contact_us') %></h2>
<%= simple_form_for #contact, :url => contacts_path do |f| %>
<%= f.input :name, :label => t('.name') if ContactUs.require_name %>
<%= f.input :email, :label => t('.email') %>
<%= f.input :subject, :label => t('.subject') if ContactUs.require_subject %>
<%= f.input :message, :as => :text, :label => t('.message') %>
<%= f.button :submit, :value => t('.submit'), :alt => t('.submit'), :id => 'contact_us_contact_submit', :title => t('.submit') %>
<% end %>
</div>
I also set config.mailer_to = "drichards2013#gmail.com."
When I submit the form, I receive a notification that the email was successfully sent.
I am trying to implement Ajax search. When the user enters the query into the text field, the data should display below it and if there are not results, a new entry should be created in the database.
I have a button next to the text field. When the user presses the button, the data in the text field should be posted to the create method which creates a new record in the database. How can I do that?
Now i am using this:
<%= form_tag song_requests_path, :method => 'get', :id => "requests_search", :class => 'well form-horizontal' do %>
<p>
<h2> I Love To Sing ...</h2>
<%= text_field_tag :search1, params[:search1], :class => 'text_field span4',:placeholder=>"Song Title", :maxlength => "250" %>
<%= text_field_tag :search2, params[:search2], :class => 'text_field span3', :placeholder=>"Album", :maxlength => "250" %>
</p>
<% end %>
<%=form_for( :song_request, :remote => true) do |f| %>
<center>
<%= f.hidden_field :title, :value => "#{params[:search1]}" %>
<%= f.hidden_field :album, :value => "#{params[:search2]}" %>
<%= f.submit " Request ", :class => 'btn btn-primary'%>
</center>
<%end%>
Functionally its working perfect, but i can't place the request button besides the text field...Thank u....
I am a user model and in my view I have:
#user = current_user
User model have an attribute with name "email".
and I want send one e-mail to multiple email address with a subject.
I have a form like:
<%= form_for (Email.new), :method => :post, :remote => true, :url => { :controller => "users", :action => "invite_friends" } do |f| %>
<%= f.text_field :address1 %>
<%= f.text_field :address2 %>
<%= f.text_field :address3 %>
<%= f.text_field :address4 %>
<%= f.text_area :subject_email %>
<% end %>
Have I that create a "email model" with attributes address and subject_email?
Check section 2.3.3 Sending Email To Multiple Recipients from the Rails Guide
How do I make a simple form association have pre data when editing?
My form:
<h1>Editing kategori</h1>
<%= simple_form_for(#konkurrancer, :url => {:action => 'update', :id => #konkurrancer.id }) do |f| %>
<%= f.association :kategoris %>
<%= f.button :submit, :value => 'Edit konkurrence' %>
<% end %>
You almost did it:
<%= f.button :submit, :value => 'Edit konkurrence', :data_pre => "whatever here" %>
Your best bet is to do something like this in your controller:
def edit
#konkurrancer = Konkurrancer.new(:title => "hello wurld", :description => "blah blah blah", :nuclear_level => 10)
end
Then your form should automatically populate these values as "pre data".
I have a web form to which I want to take a parameter from the URL and add it to the web form as a hidden field on the form.
<%= form_tag(:action => 'create') do |f| %>
<%= text_field_tag :email,"Your email address...", :class => "text", :id => "email", :name => 'email',
:onFocus => "change(this,'#222222'); this.value=''; this.onfocus=null;", :size => "26" %>
<%= hidden_field_tag :ref_code, :id => 'ref_code', :name => 'ref_code', :value => params[:ref_code] %>
<%= submit_tag "Enter To Win", :class => "button-positive submit" %>
<% end %>
If I just do a:
<%= params[:ref_code] %>
I get the value I want which is a five character alphanumeric, however when I use it in the form, I get the full hash description:
{:id=>"ref_code", :name=>"ref_code", :value=>["k53e5", "home", "index2"]}
Why? I tried .values, .to_s, and other ways of getting by key and I always get the full hash instead of just the value. What am I doing wrong? Thanks.
http://apidock.com/rails/ActionView/Helpers/FormTagHelper/hidden_field_tag
hidden_field_tag(name, value = nil, options = {})
<%= hidden_field_tag :ref_code, params[:ref_code], { :id => 'ref_code', :name => 'ref_code' } %>