I have a problem showing star rating on Ruby on Rails 6 using jquery. Stars dont show up - ruby-on-rails-6

this is the form im using that is where to permit select stars for review.
<%= simple_form_for([#restaurant, #restaurant.reviews.build]) do |f|%>
<div id="rating-form">
<%= f.input :rating %>
</div>
this is the javascript / j query code for the stars
<script>
$('#rating-form').raty({
path: '/assets/',
scoreName: 'review[rating]'
});
</script>
i have tried changing the directory, i have all dependencies required, gems. But still cant made them work. Any help, please?

Related

Rails 4 - Bootstrap themes and crazy CSS

I have a rails 4 app.
I've been struggling for MONTHS to figure out how to incorporate a bootstrap theme. I thought using a design template might help me structure my content, but it is causing me a world of pain. I just can't figure out how to work with it.
Everything has been incorporated into the pipeline, but now I have instances of CSS that isn't in my code, being imposed.
For example, in my new user registration form, I have a submit button that has:
<div class="form-actions">
<%= f.button :submit, "Sign up", :class=>'btn btn-info' %>
</div>
The info button is blue. When I load the page, it shows with now background colour.
When I load localhost and inspect the element, I get this:
<input type="submit" name="commit" value="Sign up" class="btn btn-default btn btn-info">
The btn btn-default is not part of my code, but somehow it is being imposed.
Does anyone know how to solve this problem. I've torn my hair out for weeks trying to figure this out.
MORE INFO:
When I inspect the code, it shows the attributes of btn btn-info as struck out. I understand this to mean that a closer CSS tag has overridden that element, but the tag that inserts that CSS tag is the last in the list. How can there be anything closer? And if there is something, why doesn't it show in the inspector?
Are you using simple_form ? If so, take a look in your config/initializers/simple_form.rb (or simple_form_bootstrap.rb if you used the flag --bootstrap at the generation, which I think you did)
By default, Simple Form apply a specific wrapper (see documentation here to make your own).
If you just need this one button, either way, you have to specify it like so :
<%= f.input :username, input_html: { class: 'btn btn-info' } %>
You have the same helper for the generated label :
<%= f.input :username, label_html: { class: 'my_class' } %>
Now, for a button, apparently doing simply this should do the trick (according to the documentation):
<%= f.button :submit, "Custom Button Text", class: "btn btn-info" %>
Don't hesitate to have a look at the (well made) documentation here (once again, assuming you use Simple Form :-) )
Check simple_form_bootstrap.rb in your initializers and remove 'btn-default' class from
SimpleForm.setup do |config| config.button_class = 'btn btn-default'
Use e.g. your own style there - if you want it applied for all buttons. Alternatively, make this option an empty string and apply individual specific classes for each separate button:
<%= f.button :submit, class: "btn btn-specific" %>
The config value is added to button classes here
I don't see easy way to remove this class output for single specific control. Either remove it globally or override selectors for this style in your case.
See this - you can't individually remove btn-default class - need to remove it in general config file if you need

ASP.NET View Engine Won't Render Inline ViewBag

I'm working on an ASP.NET MVC app. I'm trying to put a value in the ViewBag and write it out to the view. In an attempt to do that, I'm using the <%= ViewBage.Location %> syntax as shown below:
<article>
<h2>My Title</h2>
<section>
I see that you live in<%= ViewBag.Location %>.
</section>
</article>
When I run this page, I do not get the rendered view. Instead, I see:
I see that you in <%= ViewBag.Location %>.
Its like the view engine isn't parsing the page. However, I have no idea why this would happen. Can someone please tell me how I can get this resolved?
Thank you
Instead of writing
<%= ViewBag.Location %>
write it as
<%: ViewBag.Location %>
if you are using aspx engine(as it is likely to be as per your question)
for razor engine write it as :
#ViewBag.Location

Format CSS output in Rails

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

Rails 3 Ajaxful_rating Styling Issue

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.

Rails 3 link_to generator for :post, :put, & :delete?

I recently ran into this problem: Rails 3 link_to (:method => :delete) not working
In which I was confused why my link_to 'test', test_path(:test => test), :method => :post wasn't working (why it was GETting rather than POSTing). As the post above suggests, it was because I didn't have the Rails javascript files, which handles dynamically making the form on-the-fly for :post, :put & :delete.
I'm not sure I especially like relying on javascript to do this for me, as I'd like my app to be fully functional with javascript disabled; it's how I like to develop (so I know I've got all my Rails programming functionality works correctly), and when I do wire my app up with javascript, I don't have to worry about duplicating this functionality, since I usually wipe the stock javascripts file generated by Rails.
I read somewhere that, technically, hyperlinks (anchor elements) should only really be used for GET requests, and that buttons (as part of form elements) should be used for the other methods.
So, my two questions:
Is there a gem out there that will rewrite any link_to ... :method => in my view to a form element on-the-fly when my views are rendered?
If not, how would I hook into the view parser to write my own? (using HAML, preferrably)
Essentially, what I would like is to write this in my HAML file:
= link_to 'Test Link', some_path(:with => some_resource), :method => :post
... and have my rendered HTML output come out with this:
<form action="some_path?with=some_resource" method="post">
<!-- insert appropriate _method hidden field here -->
<!-- add appropriate csrf token and whatnot -->
<button type="submit">Test Link</button>
</form>
... so that all the link_to helpers with defined methods (thus, will not affect plain links whose verb is GET) will work without javascript?
I'd also appreciate any thoughts about the why part of this question, specifically why the Rails team decided to keep this functionality tied to javascript rather than doing this through pure HTML?
It seems that you really want a single element form (in this case, a button). If so, you want the button_to helper:
button_to 'Test Link', some_path(:with => some_resource), :method => :post
This will generate a form with an input[type=submit] element inside of it.
Without Javascript, you cannot have a hyperlink that will submit using a HTTP verb other than "GET."
If you need more style / control of the form being rendered by button_to, you can do something like this:
module LinksHelper
def link_form(text, destination, options = {})
form_tag(destination, :method => options.delete(:method)) do
<<-HTML
<!-- some HTML code here -->
<button type="submit">#{text}</button>
<!-- some more HTML code here -->
HTML
end
end
end

Resources