I'm using the ajaxful_rating gem for a user rating system in my rails app and I came across a weird styling issue:
As you can see there's much too many stars, there shouldn't be more than 5. I used Ajaxful_rating before in a previous app and didn't run into this problem. I recently started using Twitter Boostrap but as far as I can tell there aren't any styling conflicts as I removed every css link except the one needed for ajaxful_rating and I had the same issue.
Here's my view:
<dl>
<% Upload.by_ratings.limit(5).each do |upload| %>
<dt><%= link_to truncate(upload.name, :length => 55), upload%></dt>
<dd><%= upload.user.username %> - <%= ratings_for upload, :static %></dd>
<% end %>
</dl>
Has anybody ran into this problem before?
The problem was that I was directly linking to the css in my layout. I had forgotten that I needed to call the helper method ajaxful_rating_style instead.
place <%= ajaxful_rating_style %> in your javascripts.
Related
I have two repositories for the same project (long story - I'm trying to learn well, so I wanted to do it again for good measure). In one project, there is a confirm message before deleting, and there's a glyphicon trashcan on the delete button as well. In the other (current) one, neither the confirm message nor the trashcan are working (but the song does indeed delete).
The main issue here is not the trashcan, but rather that data { confirm: ... } is not working.
In the working version, the code looks like this:
<td><%= button_to delete_song_path(song_id: song.id), data: { confirm: "Are you sure?" }, class: 'btn-mini btn-danger btn' do %>
<i class="glyphicon glyphicon-trash"></i>
<% end %></td>
In the other non-working version, the code looks like this:
<td><%= button_to destroy_user_song_path(#song), data: { confirm: "Aight, are you sure?" }, class: 'btn-mini btn-danger btn' do %>
<i class="glyphicon glyphicon-trash"></i>
<% end %></td>
For the trashcan, I did some "reverse elimination" of the working version, and found that although I have all the same bootstrap gems downloaded, the line of code that made the trashcan stay / go away was `#import "bootstrap-sprockets";' in application.css.scss. However, doing the same thing in the other project didn't work, so it must be the fact that in the working version, there are glyphicon files in the public-fonts file. If that's the culprit, I'll deal with that later once I have all the other base functionality down.
Thanks!
I'm going to go ahead and answer this since I got it to work: I'm not 100% sure on the exact cause of the problem, but what I do know is that I decided to simplify things and get rid of all bootstrap gems, instead opting to use a CDN file from netdna.bootstrap.com for bootstrap 3.3.7, and everything fixed itself.
So in sum, simple seems to be the best way to go for those like me who have little to no experience. As a side note, I also defined a helper file in the helper directory in order to define a variable for the bootstrap version. This way, in the future I can switch versions of bootstrap by simply replacing the variable with the correct version.
I currently have a website with a typical homepage that uses it's own css file and then the rest of the site using one other css file. Could anyone advise on the best way to tailor my Rails app to meet these requirements?
I currently have a welcome controller with a welcome css file but not sure how to link all my other controllers to a main css file.
Thanks
Just put all your css files in
app/assets/stylesheets
then in the views use:
<%= stylesheet_link_tag "the_css_file_name_with_no_extension" %>
Actually, css files and assets in general don't get associated with controllers, but with views.
I suggest you have a read to:
http://guides.rubyonrails.org/layouts_and_rendering.html
If you want to use your controllers, you can define a global variable, and use it to conditionally include different stylesheets in your application.html.erb.
Something like:
app/views/layouts/application.html.erb
<% if #css = "main" %>
<%= stylesheet_link_tag "main" %>
<% else %>
<%= stylesheet_link_tag "application" %>
<% end%>
where #css is set to "main" in your main controller.
I'm building a small rails app that saves CSS snippets. I have a controller that allows the user to 'get' my_app.com/styles.css, which outputs plain text of all css snippets that have been entered. Is there a way I can "prettify" that css as the view is rendered? Or do I need to use some sort of javascript plugin? Or even if I could "prettify" it when it's saved in the first place. I've seen some similar server side techniques used with CSSTidy, but that's PHP only.
Edit:
Here's how I'm rendering the css view:
In my routes.rb
get 'styles', to: 'styles#snippets'
In my controller
class StylesController < ApplicationController
def snippets
#entries = Entry.all
end
end
In my view (snippets.css.erb)
<% #entries.each do |entry| %>
/* <%= entry.name %>
======================================*/
<%= entry.css %>
<% end %>
This outputs a file with a tag and then each CSS snippet. The whitespace is just weird. I don't want to rely on the users's input to properly render the CSS indentation on the output. I'd rather format it on the output to be indented nicely.
you can look at a couple of options
highlight gem
coderay railscast
Pygments.rb
I am creating an application where I am having many views but they all have to use a single css...
I placed my css code in assests\stylesheets\application.css
and in my view head part I am adding:
<%= stylesheet_link_tag 'application.css' %>
but stil it is not working
Try using:
<%= stylesheet_link_tag 'application' %>
Note the lack of .css
See this answer https://stackoverflow.com/a/10492888/950890
I've run into an issue where a third-party component appears to be interfering with Response.Write and causing any content within Response.Write("") to render before any of the other html. For example:
<html><head><title><% Response.Write("HELLO WORLD") %>
will render as
HELLO WORLD<html><head>...
However, any content rendered using <%= %> blocks will work correctly. The below code will work perfectly:
<html><head><title><%="HELLO WORLD"%>
I always assumed that <%= was simply shorthand for Response.Write. From what I've been able to find on MSDN I now understand that it <%= is eventually converted to Response.Write, but apparently there are a few steps inbetween.
Does anyone have a guess as to why the two would render differently or point me to some documentation/info that explains how <%= %> blocks are handled?
Update: The control that was causing the issue was the Telerik AjaxManager control from the 2009 Q1 release. Upgrading to the Q2 control resolved the problem.
Unfortunately I don't have access to the source so I haven't been able to figure out why the control was causing this behavior. The issue has been resolved but I am still very curious as to why it existed in the first place.
<%= "foo" %> is turned into Response.Write("foo"); once it is compiled. You can verify this by digging through the ASP.NET Temporary Files folder and using Reflector to decompile the dll's you find.