I've added a custom engine into my refinery app with an image field. It all links up great and in the admin areas I can add images to it, etc.
I have a question about adding said images to a view however. At the moment I have the following code in a view:
<img src="<%= project.picture.url %>" alt="Image description" />
This displays my image nicely (although its probably not the best method - tips welcome) but I wanted to know how to access the thumbnail of that image. I noticed in others areas of refinery you can call a thumbnail method on an image object.
<%= image_fu image, ::Image.user_image_sizes[thumbnail.to_sym],
:class => "brown_border",
:class => "current_picked_image" %>
Please could someone run me through the steps of how to achieve this. The code snippet above comes out of the image_picker page code. Being quite new to rails I'm not sure how I would achieve this in my own page.
Thanks in advance for your help!
With image_fu:
<%=link_to (image_fu project.picture, '160x104'), project.picture.url %>
Related
I am using rails 3. When implementing CMS, the body was supposed to displays the following:
<h1>Welcome to our home page</h1>.
but display the text with its tags.
In my views/viewer/show.html, I placed the following code: <%= #page.body %>.
What can I do so solve this?
Rails does this to protect you from XSS attacks. To prevent the tags from showing literally, you can use html_safe:
<%= #page.body.html_safe %>
Only use html_safe if you understand the consequences! You maybe opening up your application to XSS attacks if you don't.
It's confusing what you are trying to achieve.
If all you want to show is a line in that page, then:
In your app/controllers/viewer_controller do:
#message = "Welcome to our home page"
In you view app/views/viewer/show.html do:
</html>
<body>
<%= #message%>
</body>
</html>
I am new to Ruby on Rails and am trying to use the gmaps4rails gem. The longitude and latitude show up automatically but the map is not appearing. If I look at the page source info it seems like the map is being called and created so I'm not sure why it's not showing up.
This can be seen here:
<script src="//maps.google.com/maps/api/js?v=3.8&sensor=false&client=& amp;key=& amp;libraries=geometry&language=&hl=®ion=" type="text/javascript"></script>
<script src="//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js" type="text/javascript"></script>
<script type="text/javascript">
Gmaps.map = new Gmaps4RailsGoogle();
Gmaps.load_map = function() {
Gmaps.map.map_options.auto_adjust = true;
Gmaps.map.initialize();
Gmaps.map.markers = [{"lat":40.8217303,"lng":-73.9551369}, {"lat":41.4925374,"lng":-99.9018131},{"lat":50.3429668,"lng":18.5540869}];
Gmaps.map.markers_conf.do_clustering = true;
Gmaps.map.create_markers();
Gmaps.map.adjustMapToBounds();
Gmaps.map.callback();
};
Do I need to include some other files in my document to show the map? And where would those documents be? I am using Ruby 1.9.3 and Rails 3.2.12.
I see this type of question has been asked and answered many times, but I haven't been able to get a solution from those answers. Thanks for any help.
UPDATE:
Here is my view:
<br />
<%= link_to 'New Bathroom', new_bathroom_path %>
<%= gmaps4rails(#json) %>
Model:
acts_as_gmappable
def gmaps4rails_address
address
Controller:
def index
#bathrooms = Bathroom.all
#json = Bathroom.all.to_gmaps4rails
respond_to do |format|
format.html # index.html.erb
format.json { render :json => #bathrooms }
end
end
and application.html
<%= yield %>
<%= yield :scripts %>
<%= stylesheet_link_tag 'gmaps4rails' %>
</body>
</html>
One thing I'm wondering is if I need to copy some assets to the app. It says on the github site.
"""""""""""""""""""""""""""""""""""""""""
gmaps4rails.css will be copied to your app after you run the Rails generator. Be sure to require this file in your view for your first steps.
For Rails 3.0.x or without assets pipeline:
<%= stylesheet_link_tag 'gmaps4rails' %>
"""""""""""""""""""""""""""""""""""""""""""
Since I don't see the gmaps4rails.css file I wonder if that's the problem. Thanks for helping.
Post Debugger Details:
Yeah that's true. I have almost no experience with this stuff. I got Firebug as you recommended and discovered that when I glide over the page the google scripts in the debugger never get highlighted. I see that it did try to make a call to googleapis.com But the time for the different actions are zero, except for blocking and waiting. This makes me think nothing was sent from the google server. Under Get gmaps4rails.css it looks in my app/asset folder and has a 404 error. I'm learning how to understand all this info, and if I'm correct it seems like the server request to google was blocked for some reason and it thinks my css file is in the asset folder. If I am correct I really have no idea where to go from here. Please tell me what info would help make this problem clearer.
You need to run 'rails generate gmaps4rails:install'. That will supply the missing bits (and the css will be sourced automatically in rails 3.2).
After that, you should be good to go (based on the original question, and barring any subsequent changes).
I think this is a simple problem but I do not know how to phrase it to get a sample solution from a search engine.
Instead of allowing profile image uploads/gravatars on my website I would like to store links to images in the profile db table and embed those images in the profile show page view.
My initial thought is just to have a string url filed in the db. From there I do not know how rails will parse the string url and render the image.
Any suggestions are greatly appreciated.
If you have a link to the image stored as a link on the profile, then in your view you could do something like this:
Add image_link to Profile model
In controller
def show
#profile = Profile.find(params[:id])
....
end
In view
<%= image_tag #profile.image_link %>
Here is another Newbie question on Rails 3: I have a model called "Activity". On the show.html.erb page of an activity, I show the comments that belong to this activity as a partial:
<%= render :partial => #activity.comments %>
How the comments look like is in the _comment.html.erb file.
My question: How can I paginate the comments for an activity with Kaminari?
Thanks very much in advance!
Lets assume params[:page] is the page number for your comments. You would do something like #activity.comments.page(params[:page]). I suggest you read https://github.com/amatsuda/kaminari, the README contains pretty much everything you need.
Hey,
I'm pretty new to rails and for learning effect, I try to implement my own authorization system.
Right now I'm having a Page Controller to control some static pages and nothing more, and a Session Controller where I plan to implement most of the authorization process.
My problem is, I have no clue how to get my partial to use the sessions-controller, when I add it to one of the static pages controlled by the pages controller.
It stated out with this http://ruby.railstutorial.org/chapters/sign-in-sign-out#top but i don't want it on an extra page.
so I tried setting the routes and I got an exception "no path found for '/'" as soon as I deleted "resources :sessions" it worked fine again.
my partial looks like this:
<%= form_for(User.new) do |f| %>
<%= f.submit "Login" %>
<% end %>
there's also a div class="action" block around the submit but can't find out how to escape it
this is included into my home via
<%= render 'sessions/new' %>
Thanks for your help
edit my solution:
I added to routes.rb:
resources :sessions
Furthermore I changed form_for(#user) to
<%= form_for(:session, url => sessions_path)
so this works.
I Highly recommed that you look at the railscast http://railscasts.com/episodes/250-authentication-from-scratch , it will give you an idea how to create authentication without forgetting some important steps.
Then you can use the gem devise which is an excellent authentication gem.
Have you tried putting your functions and everything for authentication within a Session Helpers file? Then, in your Application Controller if you add "include SessionsHelper" this should give you access to all the helper functions from Session that you should need