How to create a button with label and image in Rails3?
This code only show an image:
<%= link_to image_tag("newRevision.png"), {:controller => :review_transitions, :action => :show_step}, {:class => "navBtn"} %>
but... the image with text?
<%= link_to "example_text"+image_tag("newRevision.png"), {:controller => :review_transitions, :action => :show_step}, {:class => "navBtn"} %>
thanks!
I think it may be something along these lines
<%= link_to image_tag('image/someimage.png') + "Some text", some_path) %>
Related
I´m new with ruby and I´m trying to insert an awesome-font icon inside a link using rails 3.2.15
This is my code
<%= link_to tweet_path(tweet), method => :delete, :confirm => 'Are you sure?' do %>
<i class="icon-trash"></i>
<% end %>
<%= link_to edit_tweet_path(tweet) do %>
<i class="icon-pencil"></i>
<% end %>
I don´t know what I'm doing wrong.
Thank you in advance.
You can do this:
<%= link_to raw('<i class="icon-trash"></i>'), tweet_path(tweet), method => :delete, :confirm => 'Are you sure?' %>
you can do this:
<%= link_to content_tag(:i,nil, :class => "icon-trash"), tweet_path(tweet), method => :delete, :confirm => 'Are you sure?' %>
<%= link_to content_tag(:i,nil, :class => "icon-pencil"), edit_tweet_path(tweet) %>
hope this helps you
I have a booking model, I want the user to confirm/reject a booking by clicking on one link or the other. I'm trying to avoid having to create a form.
here is how I tried implementing it:
<% #bookings.each do |booking| %>
<%= link_to "Confirm", appointment_booking_path(#appointment, booking, :status => "confirmed"), :method => :put, confirm: 'Are you sure?', :class => 'btn btn-success' %>
<%= link_to "Reject", appointment_booking_path(#appointment, booking, :status => "rejected"), :method => :put, confirm: 'Are you sure?',:class => 'btn btn-danger' %>
<%end%>
I am getting this error upon clicking on one of the links:
NoMethodError in BookingsController#update
undefined method `[]' for nil:NilClass
app/controllers/bookings_controller.rb:64:in `update'
Bookings is nested within appointments. Here is my rake Routes:
PUT /appointments/:appointment_id/bookings/:id(.:format)
appointment_booking GET /appointments/:appointment_id/bookings/:id(.:format)
edit_appointment_booking GET /appointments/:appointment_id/bookings/:id/edit(.:format)
BookingController Update action:
line 64* #appointment = Appointment.find(params[:booking][:appointment_id])
#booking = Booking.find(params[:id])
Let me know if you need any more information. Thank you in advance.
Look carefully at your rake routes, and you'll see it's appointment_booking and not appointment_bookings (i.e. no s at the end of bookings).
You'll also need to pass in the appointment instance as the first argument. Assuming your appointment is called #appointment, try this:
<% #bookings.each do |booking| %>
<%= link_to "Confirm", appointment_booking_path(#appointment, booking, :status => "confirmed"), :method => :put, confirm: 'Are you sure?', :class => 'btn btn-success' %>
<%= link_to "Reject", appointment_booking_path(#appointment, booking, :status => "rejected"), :method => :put, confirm: 'Are you sure?',:class => 'btn btn-danger' %>
<% end %>
I have a simple form that looks like this:
<%= simple_form_for #study,:url => studies_path, :html => { :class => 'form-horizontal' } do |f| %>
<%= f.input :category, :collection => #categories, :label => "Category", :selected => #categories.first %>
<%= f.button :submit, t('add_form'),:class => 'btn-primary' %>
I want to add a new field in that form that will be merely visual sugar. It will be a helper to dynamically change the :category field.
How do I do that?
Use text_field_tag or whichever other _tag helper to generate a form element without attaching it to any specific attribute of the model:
<%= simple_form_for #study,:url => studies_path, :html => { :class => 'form-horizontal' } do |f| %>
<%= f.input :category, :collection => #categories, :label => "Category", :selected => #categories.first %>
<%= text_field_tag :blah %>
<%= f.button :submit, t('add_form'),:class => 'btn-primary' %>
<% end %>
I have a REST resource called Greetings.
Here is my routes file:
resources :greetings
I have a form to create or update a greeting as follows:
<%= form_tag(#greeting, :remote => true, :id => 'greeting_form') do %>
<%= text_area :greeting, :content, :rows => 3, :placeholder => "Type your message..." %>
<% end %>
note: I am using form_tag because this form also collects user data.
This is supposed to create a hidden field with method=> put but its not so it can't find the route.
Any ideas how I can get this to submit to the update action?
Just write
<%= form_tag(#greeting, :remote => true, :id => 'greeting_form', :method => :put) do %>
and everything should be working.
You can use form_for tag and still collect user data like this:
<%= form_for #greeting, :validate => true do |f| %>
<%= f.text_area :content, :rows => 3, :placeholder => "Type your message..." %>
<%= f.fields_for #user do |u| %>
<%= u.text_field :name %>
<% end %>
<% end
<%= question.name %>
Created <%= time_ago_in_words(question.created_at) %> ago.
<% if :action == "edit" then %>
<%= link_to "delete", question, :method => :delete,
:confirm => "You sure?",
:title => question.name %>
<% end %>
Use action_name like so:
<% if action_name == 'edit' %>
<%= link_to 'delete', question, :method => :delete, :confirm => 'You sure?', :title => question.name %>
<% end %>