I'm trying to use the erb template on my angular templates folder, but the functionality is limited, for example,
The <% link_to
is working
but devise methods or even raw('sdmdslkc') pops an error that the method is not found.
for example
<%= link_to('Logout', destroy_user_session_path, :method => :delete) %>
work on views but not in angular templates (says destroy_user_session_path method not found)
Whats missing ? is it fixable?
let me see if i understand, u have some template with some tags that belongs to another language that is not angular, html, or js. if so then it is not fixable because angular sends an ajax to bring that html file and injects it to your page, alot after any server has rendered any part of the page.
my suggestion for a work around is to try and tell angular to take a server page, say it was with asp.net and i would like some server tags i would tell angular that the template is somepage.aspx while making sure that my page evetually returns plain html.
Related
I am using CarrierWave to upload static HTML templates to certain user profiles on my webpage.
I am trying to render the HTML file on the user's home page once they log in. The Path for the HTML file after uploading is:
/uploads/profile/curation/8/User_Content.html
I'm new to rails and I thought I'd just be able to
<%= render /uploads/profile/curation/8/User_Content.html %>
to get the html to render, but I guess that only works for partials, which this is not.
Any advice?
You can use render_to_string. Please have a look over here. http://russbrooks.com/2009/11/18/embed-a-static-hmtl-page-in-a-rails-view
In your controller you can redirect to the page you want:
redirect_to "/uploads/profile/curation/8/User_Content.html"
I'm using Rails 3.1 here, and I've got the following code in my view:
<%= link_to "again!", main_pick_path,{:method => :post, :var => #var} %>
The idea is to create a link (not a button) which, when clicked, calls the pick action of the main controller, passing the value of #var in params via a POST request.
This code generates the following HTML in my browser:
a href="/main/pick" data-method="post" rel="nofollow" var="foo">again!</a>
However when I click the link I am still sending a GET request. Is this a limitation of my browser, Chrome? From a design standpoint, should I be using a GET request instead and putting the variable into the URL? Are hyperlinks simply incapable of using the POST method? Is there life after death?
Thanks in advance
You can only do this with AJAX or firing a FORM. The tag A cant do a POST "alone".
So I am storing the whole embed code from youtube into my database and then outputting it like this.
<%= raw(people.video) %>
which outputs the general iframe tag copied from youtube:
<iframe src="foo" width=400 height=380></iframe>
the problem is that it actually displays that tag instead of embedding the video into the page itself. I can get around this just by storing the src in the database.... but this is part of a mini cms system and the site admins would find it much easier just to copy and past the embed code from youtube. Is there someway I can specify for the iframe to actually render instead of just spitting out the html on the page?
You can use the raw method to render the HTML of a string, are you storing it that way? You can also try the RedCloth gem - I was able to get this working like so:
<%= raw RedCloth.new(#page_content.content).to_html %>
Which allowed for my custom CMS to use the Textile markup
http://en.wikipedia.org/wiki/Textile_%28markup_language%29
I'm not 100% on what you're seeing, since raw should render HTML, but you might also try to include the embed tag using a JavaScript.write, since there are some issues related to Flash objects embedded in HTML vs JavaScript.
Let me know if this doesn't work, and if so, can you provide screenshots or copy what you're seeing on the page?
I have watched railscasts about unobtrusive javascript and read numerous tutorials, but two things about unobtrusive javascript in Rails3 still confuses me:
End-point for simple javascript (hiding some elements, adding CSS class, ...)
Passing arguments to JS
Let me clarify this with sample code. I want to make a link which fades out some element with id "sample":
link_to 'Fade sample', url, :remote => true
What should be the url so it can execute JS? Should it be new action in controller named for example 'javascript' so it can access JS in javascript.js.erb which contains:
$('#sample').fadeOut();
Also, second question about ujs is related with passing arguments to JS (timeout, for this example). I can write:
link_to 'Fade sample', url, :data-timeout => 1500, :remote => true
but don't know how to access data-timeout in javascript.
I am using Rails 3.0.5, JQuery 1.5.2 and jquery-ujs.
I would try to answer one by one.
url in link_to. It would be a url hash for any resource in the application. Lets suppose you have specified resources :foos in the routes.rb, it will create 6 urls for CRUD operation. You can pass these to the urls by the methods like new_foo_url, foo_url(#foo) or foos_url. Even you can pass a hash manually like {:controller=>:foos_controller, :action=>:index}, also you can pass multiple parameters to the hash like {:controller=>:foos_controller, :action=>:index, :param1=>"value1", :param2=>"value2"}. Also you can pass strings urls like foos/new, foos/1 etc
You can access custom tag attributes with jQuery very easily. for example you want to access anchor with id="link", you can $('#link').attr("data-timeout"). If you don't know what exactly the id is, but you know it have an attribute you can call $("a[data-timeout]").first().attr('data-timeout')
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